+ All Categories
Home > Documents > Big Picture Testing

Big Picture Testing

Date post: 23-Feb-2016
Category:
Upload: didier
View: 52 times
Download: 0 times
Share this document with a friend
Description:
Big Picture Testing. Fluently specifying complex scenarios for integration tests Chris Edwards. Roadmap. Integration Testing What it is, and common problems Qualities of a good unit test Principles for database-facing tests Practices Patterns and Code. What the heck is…. - PowerPoint PPT Presentation
Popular Tags:
29
Big Picture Testing Fluently specifying complex scenarios for integration tests Chris Edwards
Transcript
Page 1: Big Picture Testing

Big Picture TestingFluently specifying complex

scenarios for integration tests

Chris Edwards

Page 2: Big Picture Testing

Roadmap• Integration Testing

– What it is, and common problems• Qualities of a good unit test• Principles for database-facing tests• Practices

– Patterns and Code

Page 3: Big Picture Testing

INTEGRATION TESTING?What the heck is…

Page 4: Big Picture Testing

What is Integration Testing?

“Integration testing … is the activity of software testing in which individual software modules are combined and tested as a group. It occurs after unit testing and before system testing.”

-Wikipedia

“If it hits the database, it’s not a unit test”-Some Smart Guy

Page 5: Big Picture Testing

Some Assumptions• Tests are automated (CI)• Using a unit test framework• Tests access the database

Page 6: Big Picture Testing

Common Problems• Brittle• Monster test “SetUp” methods.• “Who changed my data?”• Spend more time fixing tests than writing code

Page 7: Big Picture Testing

QUALITIES OF A GOOD UNIT TEST

What is a good test?

Page 8: Big Picture Testing

Qualities of a Good Unit Test

• Clear• Measurable• Meaningful• Atomic• Self-Contained• Robust• Specific

• Repeatable• Isolated• Order-Independent• Fast• Fine-Grained• Autonomous

Page 9: Big Picture Testing

Integration Tests Differ

Unit Tests• Fine Grained• Fast• Run constantly• Never involves

database• Very little to set up

Integration Tests• Coarse Grained• Slower• Run less often• Often involves

database• Can be a pain in the

#&*!

Page 10: Big Picture Testing

PRINCIPLES FOR DB FACING TESTS

This ain’t your momma’s unit test.

Page 11: Big Picture Testing

Principle of Data Self-Sufficiency“A test should insert any data it needs into the database.” Stated another way: “A test should not depend upon any pre-existing data in the database.”

• Supported Qualities– Atomic– Robust– Clear

Page 12: Big Picture Testing

Principle of Intrinsic Data Assurance“For data that is intrinsic to the system (required for operation), tests should be written to assert its existence.”

• Supported Qualities– Robust– Clear– Specific

Page 13: Big Picture Testing

Principle of Side-Effect Free Execution“A test should rollback any changes it makes to the database regardless of whether the test passes or fails.”

• Supported Qualities– Repeatable– Robust

Page 14: Big Picture Testing

PRACTICESPractice makes perfect…

Page 15: Big Picture Testing

Pattern: Auto-Rollback Test Base Class“Ensure Side-Effect Free Execution of tests by deriving them from a base class that starts a transaction on setup and rolls it back on teardown.”

Supported Principle: Side Effect Free Execution

Page 16: Big Picture Testing

Pattern: Intrinsic Data Test“Ensure data intrinsic to the execution of the system is not missing or invalid by asserting its existence in a test.”

Supported Principle: Intrinsic Data Assurance

Page 17: Big Picture Testing

Data Insertion Patterns• Inline Insert• Big Friggin Insert• Anonymous Objects• Object Mother• Fluent Builder

Supported Principle: Data Self-Sufficiency

Page 18: Big Picture Testing

Pattern: Inline Insert“Insert data required for a test by executing multiple insert statements during test setup.”

Supported Principle: Data Self-Sufficiency

Page 19: Big Picture Testing

Pattern: Inline Insert

Advantages• Quickest

Disadvantages• Violates DRY• Is Not Clear• Quickly becomes

unmaintainable

Page 20: Big Picture Testing

Pattern: Big Friggin Insert“Insert data required for multiple tests by using a common data set created by executing multiple insert statements that is shared across tests.”

Supported Principle: Data Self-Sufficiency

Page 21: Big Picture Testing

Pattern: Big Friggin Insert

Advantages• Solves DRY problem of

Inline Insert

Disadvantages• Is Not Clear• Quickly becomes

unmaintainable

Page 22: Big Picture Testing

Pattern: Anonymous Object“Remove unnecessary detail from a test by randomly generating unimportant data.” Or “Clarify your tests by only specifying the things you need.”

Supported Values:– Clear– Specific

Page 23: Big Picture Testing

Pattern: Anonymous Factory (Object Mother)

“Simplify creation of graphs of complex objects by creating a central object to manage their creation.”

Supported Values:– Clear– Specific

Page 24: Big Picture Testing

Pattern: Anonymous Factory (Object Mother)

Advantages• Adheres to DRY• Easy to develop• Easy to understand (clear)• Deep graphs are simplified

(auto-created dependencies)

Disadvantages• Can become difficult to

maintain (monster object)• Violates:

– SRP• Creates all objects

– OCP• All methods in one big object

Page 25: Big Picture Testing

Pattern: Fluent Builder“Simplify and clarify creation of complex graphs of objects by creating a fluent interface (DSL) to describe and build them.”

Supported Values:– Clear– Specific

Page 26: Big Picture Testing

Pattern: Fluent Builder

Advantages• Extremely easy to use

– Discoverable interface– Nesting simplifies complex

graphs• Much easier to understand

(even for complex graphs)• Adheres to:

– SRP• One builder per class

– OCP• Adding new builders is easy

Disadvantages• Can be more challenging

to develop up front• Concept of DSL may take

some “getting used to”

Page 27: Big Picture Testing

Fluency.NET

“A framework for creating a .NET fluent interface for building anonymous object graphs for testing.”

Source:http://github.com/ChrisEdwards/FluentObjectBuilder/

Blog:http://ChrisEdwards.dreamhosters.com/

Page 28: Big Picture Testing

Additional Resources• “xUnit Test Patterns: Refactoring Test

Code” – Gerard Meszaros

• “Domain Specific Languages”– Work in Progress by Martin Fowler– http://martinfowler.com/dslwip

Page 29: Big Picture Testing

About Me

Chris EdwardsSenior Developer, BancVueEmail: [email protected]:

chrisedwards.dreamhosters.comTwitter: @cedwards

BancVue Web: www.bancvue.comPhone: 877.342.2557

We’re hiring C# developersSend resumes to: [email protected]


Recommended