Download presentation
Presentation is loading. Please wait.
Published byPhilomena Cunningham Modified over 9 years ago
1
Unit Tests Руслан Трифонов Omegasoft Ltd.
2
Съдържание 1.Въведение 2.Unit test patterns 2.1. Pass/fail patterns 2.2. Collection management patterns 2.3. Data driven patterns 2.4. Data transaction patterns 2.5. Performance patterns 2.6. Process patterns 2.7. Simulation patterns 2.8. Stress test patterns 3.Ресурси
3
Definition A unit test is a piece of code written by a developer that exercises a very small, specific area of functionality of the code being tested.
4
Scope Design Development Test and Fix Time flow Planning Unit Testing System Testing Integration Testing Functional Testing Release Testing Unit Tests and Application Lifecycle
5
Unit test framework is needed.Unit test framework is needed. Unit tests are written by developers for developersUnit tests are written by developers for developers Unit tests are released into the code repository along with the code they testUnit tests are released into the code repository along with the code they test Some facts
6
Trivial code may be omitted (property getters and setters)Trivial code may be omitted (property getters and setters) Ideally all unit tests should pass before check-inIdeally all unit tests should pass before check-in More facts
7
Code and TestCode and Test Test FirstTest First Unit Testing Approach
8
Write code Write unit test Run and succeed Code and Test Time flow
9
Pick а test Compile and Fail Write code to pass test Write enough code to compile Run test and fail Create a test list Test Driven Development Time flow Write test Remove duplication
10
Why TDD? Helps find design issues early and avoids reworkHelps find design issues early and avoids rework Writing code to satisfy a test is a focused activity – less chance of errorWriting code to satisfy a test is a focused activity – less chance of error Tests will be a more comprehensive than when written after codeTests will be a more comprehensive than when written after code
11
Unit tests improve designUnit tests improve design Unit tests are good documentationUnit tests are good documentation Unit tests enable collective code ownershipUnit tests enable collective code ownership Why Unit Tests?
12
Unit tests decrease the defect-injection rate due to refactoring / changesUnit tests decrease the defect-injection rate due to refactoring / changes Unit tests decrease the cost of the changesUnit tests decrease the cost of the changes Unit tests bring higher development velocity in the latest dev. stagesUnit tests bring higher development velocity in the latest dev. stages Unit tests enable frequent integrationUnit tests enable frequent integration
13
Development Workstation Source Code Repository Server Integration Server Publish Results Continuous Integration Check out Build Perform BVT Publish results Check-in
14
Why Continuous Integration? The time to integrate is a function of the time between two subsequent integrations Faster and cheaper integration processFaster and cheaper integration process Faster integration error recoveryFaster integration error recovery
15
Scaling Up Real Life ExampleReal Life Example Company SAS Institute Developers ~800 Environment Java, *Cruise control, CVS Code size ~15 000 000 loc 3 CVS Branches of 5 million loc each
16
Unit Test Patterns
17
Pass/fail patterns The Simple-Test PatternThe Simple-Test Pattern The Code-Path PatternThe Code-Path Pattern The Parameter-Range PatternThe Parameter-Range Pattern
18
The Simple-Test Pattern Condition A Condition B Code Expected Result Expected Failure
19
The Code-Path Pattern Code Path A Code Path B Code Paths Path Result
20
The Parameter-Range Pattern Code Path A Code Path B Code Paths Path Result Success Set Failure Set
21
Collection management patterns The Collection-Order PatternThe Collection-Order Pattern The Enumeration PatternThe Enumeration Pattern The Collection-Constraint PatternThe Collection-Constraint Pattern The Collection-Indexing PatternThe Collection-Indexing Pattern
22
The Collection-Order Pattern Unordered Data Code Containing Collection Unordered Sequenced Ordered
23
The Enumeration Pattern Enumerator (Fwd, Rev) Code Containing Collection Edged Test Collection Expected Datum
24
The Collection-Constraint Pattern Null Value Collection Container Write Test Constraints Unique
25
The Collection-Indexing Pattern Index Key Collection Container Write Test Index Tests Out Of Bounds Index Update/Delete by Index
26
Data driven patterns The Simple-Test-Data PatternThe Simple-Test-Data Pattern The Data-Transformation-Test PatternThe Data-Transformation-Test Pattern
27
The Simple-Test-Data Pattern Input Verify Results Computation Code Output Unit Test Data Set
28
The Data-Transformation-Test Pattern Input Data Set Measurements Transformation Code Validation Unit Test
29
Data Transaction patterns The Simple-Data-I/O PatternThe Simple-Data-I/O Pattern The Constraint-Data PatternThe Constraint-Data Pattern The Rollback PatternThe Rollback Pattern
30
The Simple-Data-I/O Pattern Service Read Test Write Test
31
The Constraint-Data Pattern Nullable Service Write Test Constraints Unique Default Value Foreign Key Cascading Update Default Delete
32
The Rollback Pattern Service Known State Write Test rollback
33
Performance Patterns The Performance-Test PatternThe Performance-Test Pattern
34
The Performance-Test Pattern Metric At Start Code Pass Fail Metric At End Pass criteria
35
Simulation patterns Mock-Object PatternMock-Object Pattern The Service-Simulation PatternThe Service-Simulation Pattern The Component-Simulation PatternThe Component-Simulation Pattern
36
Mock-Object Pattern Abstract Methods Mock Object Implementation Real Access Layer Implementation Factory Mode Instantiates one of
37
The Service-Simulation Pattern Test Code Simulated Service Test I/O
38
The Component-Simulation Pattern Recovery Code Component Failure Test Timeout
39
Stress test patterns The Bulk-Data-Stress-Test PatternThe Bulk-Data-Stress-Test Pattern The Resource-Stress-Test PatternThe Resource-Stress-Test Pattern The Loading-Test PatternThe Loading-Test Pattern
40
The Bulk-Data-Stress-Test Pattern Data Manipulation Data Process Pass Fail Bulk Data Performance Metric
41
The Resource-Stress-Test Pattern Test Code Set Resource
42
The Loading-Test Pattern Test Code Loading
43
Useful links Extreme Programming Extreme Programming www.extremeprogramming.org XP Programming www.xprogramming.com Unit Test Patterns Unit Test Patterns www.codeproject.com/gen/design/autp5.asp Continuous Integration Continuous Integration www.martinfowler.com/articles/continuousIntegration.ht ml Darrell Norton’s Blog Darrell Norton’s Blog www.codebetter.com/blogs/darrell.norton/articles/5033 7.aspx
44
Q & A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.