Using xUnit as a Swiss-Army Testing Toolkit (Does Unit Size Matter?) ACCU Conference 2011 Chris Oldwood

Slides:



Advertisements
Similar presentations
Unit Testing in SQL Richard Fennell Engineering Director SqlBits 6 th October 2007.
Advertisements

17. Data Access ADO.Net Architecture New Features of ADO.NET
Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
© RightNow Technologies, Inc. RightNow Connect Web Services for SOAP Chris Omland.
Acceptance Testing vs. Unit Testing: A Developers Perspective Owen Rogers Rob Styles
SQL Objects and PL/SQL. Who am I ?  Gary Myers  Oracle developer since 1994  Database Consultant with SMS M&T  Blogger since 2004 Now at blog.sydoracle.com.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
XUnit Style Database Unit Testing ACCU London – 20 th January 2011 Chris Oldwood
Execute Stored Procedure having Output Parameter and returning Result Set in Adeptia Server.
Jump into Release 1 Pepper. Goals for End of Class Project delivery Diagrams (new class & firm state, use, context, sequence) Agile cycles with SCRUM.
Chapter 15 Design, Coding, and Testing. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Design Document The next step in the Software.
Module 9: Implementing Stored Procedures. Introduction to Stored Procedures Creating Executing Modifying Dropping Using Parameters in Stored Procedures.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
XUnit Test Patterns writing good unit tests Peter Wiles.
Database Development Using TDD Chris Oldwood ACCU Conference /
Stored Procedures Dr. Ralph D. Westfall May, 2009.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Database testing Prepared by Saurabh sinha. Database testing mainly focus on: Data integrity test Data integrity test Stored procedures test Stored procedures.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
UNIT TESTING FOR SQL Prepared for SUGSA CodeLabs Alain King Paul Johnson.
Effectively Validate Query/Report: Strategy and Tool Steven Luo Sr. System Analyst Barnes & Noble Session id:
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
Testing Especially Unit Testing. V-model Wikipedia:
Session 4: The HANA Curriculum and Demos Dr. Bjarne Berg Associate professor Computer Science Lenoir-Rhyne University.
Dexterity | CONFIDENTIAL 2009 MRO | Analytics | Insights 1 Stored Procedures.
ABC Insurance Co. Paul Barry Steve Randolph Jing Zhou CSC8490 Database Systems & File Management Dr. Goelman Villanova University August 2, 2004.
Module 8: Implementing Stored Procedures. Introducing Stored Procedures Creating, Modifying, Dropping, and Executing Stored Procedures Using Parameters.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
Database Unit Test MSSQL 2008 & VS 2010 Aung Kyaw Myo.
Oracle Data Integrator Procedures, Advanced Workflows.
Effective Test Driven Database Development Gojko Adzic
1 Introduction to Database Systems CSE 444 Lecture 06 SQL in C#, Project October 5, 2007.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
G. Green 1.  Options include:  Script Files  already covered  APIs  last course topic  Database-Stored Code  our focus 2.
Testing in Android. Methods Unit Testing Integration Testing System Testing Regression Testing Compatibility Testing Black Box (Functional) White Box.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Test-Driven SQL Chris Oldwood Agile on the Beach /
Dynamic Testing.
Automated Testing in Sakai Testing applications and services in isolation and in context Josh Holtzman, UC Berkeley David Haines, University of Michigan.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 8: Applications Programming for Relational Databases Instructor’s.
App Package Folder App data Folders Local Roaming Temp Removable Storage (SD Card) Cloud Credential Locker B/ground Transfer Publishers Shared Folder.
IMS 4212: Application Architecture and Intro to Stored Procedures 1 Dr. Lawrence West, Management Dept., University of Central Florida
Mocking with Moq Tools for Easier Unit Testing SoftUni Team Technical Trainers Software University
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
19 Copyright © 2004, Oracle. All rights reserved. Coding PL/SQL Triggers.
Copyright 2015 Varigence, Inc. Unit and Integration Testing in SSIS A New Approach Scott @varigence.
Test Plans Test Driven Development – Unit test plan first Code coverage Automated Regression built as you go Debug is easier Serves as system doc – Still.
Get testing with tSQLt Practical examples and automation Steve Jones SQLServerCentral Red Gate Software.
Advanced program design with c++
SQL Environment.
TESTING TEST DRIVEN DEVELOPMENT
Data Virtualization Demoette… Custom Java Procedures
Step 1 Create Database Info activity in Adeptia Server specifying the driver, URL and user credentials information for the database in which stored.
Introduction to JUnit CS 4501 / 6501 Software Testing
Cisco Data Virtualization
Prepared Statements Function and Triggers
Test Case Structure Test Case Module(depend on framework) MocoServer
Test-Driving Your Database
Unit Testing with xUnit.net-Part-2
Introduction to JUnit CS 4501 / 6501 Software Testing
CSE 303 Concepts and Tools for Software Development
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Automated test.
Chapter 11: Integration- and System Testing
CSE 1020:Software Development
Automated test.
Presentation transcript:

Using xUnit as a Swiss-Army Testing Toolkit (Does Unit Size Matter?) ACCU Conference 2011 Chris Oldwood

Stream of Consciousness Developer Driven Testing The Essence of (x)Unit Testing Those Pesky Dependencies Code & Test Evolution in Practice

Stream of Consciousness Developer Driven Testing The Essence of (x)Unit Testing Those Pesky Dependencies Code & Test Evolution in Practice

Text Book Test string[][] tests = { { "3", "4", "+", "7" }, { "9", "1", "-", "8" }, { "2", "3", "*", "6" }, { "9", "3", "/", "3" }, }; void run_tests() { var calculator = new Calculator(); foreach(var test in tests) { var lhs = test[0]; var rhs = test[1]; var op = test[2]; var result = calculator(lhs, rhs, op); assert(result == test[3]); }

Exercise Left for the Reader External System 1External System 2External System 3 The System 42 Services Database

Unit Integration System Component Stress Lexicon of Testing End-to-End Regression White Box Black Box Characterisation Exploration

System Integration Component Unit Dependencies Feedback Unit Evolution All Regression

Stream of Consciousness Developer Driven Testing The Essence of (x)Unit Testing Those Pesky Dependencies Code & Test Evolution in Practice

Test == Specification public void Execute_Should_Elide_Agreement_When_No_Trades_Match() { var trades = new List { new Trade("trade-id", "product-a") }; var agreement = new Agreement("product-b"); var task = new PreparationTask(trades, agreement); var result = task.Execute(s_services); Assert.That(task.Agreement, Is.Null); }

Consistent Style public void a_c_sharp_test() { var arrangement = new Arrangement(); var result = arrangement.action(); Assert.That(result, Is.EqualTo(expectation)); } create procedure a_sql_test as declare arrangement varchar(100), result varchar(100) exec = = result exec "expectation" go

Minimises Dependencies MyService External ServiceDatabaseFile System Mock External Service IExternalServiceIFileSystemIDatabase Mock File System Mock Database

Promotes Arbitrary Code Execution public void Prepare_Should_Elide_Agreement_When_No_Trades_Match() { var trades = new List { new Trade("trade-id", "product-a") }; var agreement = new Agreement("product-b"); var task = new PreparationTask(trades, agreement); var result = task.Execute(s_services); Assert.That(task.Agreement, Is.Null); } LibraryEXE Stub Test RunnerLibraryTestsDebugger Custom Test Harness

Automated Testing Lowers the barrier to running tests Regression testing is implicit Build server watches your back

Stream of Consciousness Developer Driven Testing The Essence of (x)Unit Testing Those Pesky Dependencies Code & Test Evolution in Practice

Pesky Dependencies External System 1External System 2External System 3 The System Service 2 Service 1 File-System Database

xUnit Abuse Fight the Shadow Cache Invoke TearDown from SetUp Test/build failure isnt absolute

File-System (Reading) Source Control directory Build server directory Resource files

File-System (Writing) TEMP directory Output directory

Database Per-user / per-branch workspace Only need schema not data (Integration) Can reuse existing unit test database Use same code revision for compatibility Use transactions to avoid residual effects Fake tables with CSV files

Database Asserts public void AddCustomer_Should_Persist_The_Customer() { const id = 1234; const name = "name"; var customer = new Customer(...); using (var connection = AcquireConnection()) { CustomerDataMapper.AddCustomer(customer, connection); Assert.That(RowExists("dbo.Customer", " CustomerId = {0}" + " AND CustomerName = '{1}'", id, name), Is.True); }

Database SetUp/TearDown [TestFixture, TestCategory.DatabaseTest] public class SomeEntityTests : DatabaseTestBase { [TestFixtureSetUp] public void FixtureSetUp { using(var connection = AcquireConnection()) { connection.Execute("insert into thingy_table values(1, 2, 3)"); connection.Execute("test.InsertThingy(1, 2, 3)"); } [TestFixtureTearDown] public void FixtureTearDown { using(var connection = AcquireConnection()) { connection.Execute("delete from thingy_table"); connection.Execute("test.DeleteAllThingys"); }

Helper Base Class public class DatabaseTestBase { public ISqlConnection AcquireConnection() { return... }... public bool RowExists(string table, string where, string params[]) { string filter = String.Format(where, params); string sql = String.Format( "select count(*) as [Count] from {0} where {1}", table, filter); using (var connection = AcquireConnection()) { var reader = connection.ExecuteQuery(sql); return (reader.GetInt("Count") == 1); }... }

External Systems Verify API behaviour Test internal façade Reliability varies (DEV vs PROD)

Stream of Consciousness Developer Driven Testing The Essence of (x)Unit Testing Those Pesky Dependencies Code & Test Evolution in Practice

System Architecture Market DataTrade DataAnalytics The System 42 Services Database

Initial System Test Market Data Service Trade Data Service Analytics Service Calculator Test Runner System Tests [Test, TestCategory.SystemTest] public void Calculate_Answer() {... var result = c.calculate(); Assert.Equal(result, 42); }

Addressing External Risks External Market Data Service API External Trade Data Service API External Market Data Service Tests External Trade Data Service Tests Test Runner

Internal Service Design External Service API External Service Tests Internal Service External Service Facade Internal Service Tests Mock External Services Performance Test Runner Mock Service

Data Access Layer Database Public Interface Database Unit Tests Data Access Layer Data Access Layer Tests Database API Mock Database API Mock Data Access Layer

Database Public Interface External Analytics Service External Market Data Service API External Market Data Service API System Evolution Mock Market Data Service Mock Trade Data Service Mock Analytics Service Calculator Test Runner Unit / Integration / System Tests [Test, TestCategory.SystemTest] public void Calc_Answer_For_ABC_Plc() {... var result = c.calculate(); Assert.Equal(result, 41.75); } Mock Data Access Layer Market Data Service Trade Data Service Analytics Service Data Access Layer

The Oldwood Thing Chris Oldwood