1 / 44

Unit Tests

Unit Tests. Руслан Трифонов Omegasoft Ltd. Съдържание. Въведение 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

darci
Download Presentation

Unit Tests

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit Tests Руслан Трифонов Omegasoft Ltd.

  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. 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. Unit Tests and Application Lifecycle Scope Planning System Testing Integration Testing Functional Testing Release Testing Design Unit Testing Development Test and Fix Time flow

  5. Some facts • Unit test framework is needed. • Unit tests are written by developers for developers • Unit tests are released into the code repository along with the code they test

  6. More facts • Trivial code may be omitted (property getters and setters) • Ideally all unit tests should pass before check-in

  7. Unit Testing Approach • Code and Test • Test First

  8. Code and Test Write code Write unit test Run and succeed Time flow

  9. Test Driven Development Create a testlist Pick а test Write test Compile and Fail Write enough code to compile Run test and fail Write code to pass test Remove duplication Time flow

  10. Why TDD? • Helps find design issues early and avoidsrework • Writing code to satisfy a test is a focusedactivity –less chance of error • Tests will be a more comprehensive thanwhen written after code

  11. Why Unit Tests? • Unit tests improve design • Unit tests are good documentation • Unit tests enable collective code ownership

  12. Why Unit Tests? • Unit tests decrease the defect-injection rate due to refactoring / changes • Unit tests decrease the cost of the changes • Unit tests bring higher development velocity in the latest dev. stages • Unit tests enable frequent integration

  13. Continuous Integration • Check out • Build • Perform BVT • Publish results Check-in Development Workstation SourceCode Repository Server Integration Server Publish Results

  14. Why Continuous Integration? The time to integrate is a function of the time between two subsequentintegrations • Faster and cheaper integration process • Faster integration error recovery

  15. Scaling Up • Real Life Example

  16. Unit Test Patterns

  17. Pass/fail patterns • The Simple-Test Pattern • The Code-Path Pattern • The Parameter-Range Pattern

  18. Code Expected Result Condition A Expected Failure Condition B The Simple-Test Pattern

  19. The Code-Path Pattern Code Paths Path Result Code Path A Path Result Code Path B

  20. Success Set Code Paths Path Result Code Path A Path Result Code Path B Failure Set The Parameter-Range Pattern

  21. Collection management patterns • The Collection-Order Pattern • The Enumeration Pattern • The Collection-Constraint Pattern • The Collection-Indexing Pattern

  22. The Collection-Order Pattern Unordered Code Containing Collection Sequenced Unordered Data Ordered

  23. The Enumeration Pattern Code Containing Collection Edged Test Expected Datum Enumerator (Fwd, Rev) Collection

  24. The Collection-Constraint Pattern Collection Container Write Test Null Value Unique Constraints

  25. The Collection-Indexing Pattern Collection Container Write Test Index Key Out Of Bounds Index Update/Delete by Index Index Tests

  26. Data driven patterns • The Simple-Test-Data Pattern • The Data-Transformation-Test Pattern

  27. The Simple-Test-Data Pattern Data Set Input Output Computation Code Verify Results Unit Test

  28. The Data-Transformation-Test Pattern Input Data Set Validation Transformation Code Unit Test Measurements

  29. Data Transaction patterns • The Simple-Data-I/O Pattern • The Constraint-Data Pattern • The Rollback Pattern

  30. The Simple-Data-I/O Pattern Read Test Service Write Test

  31. The Constraint-Data Pattern Service Write Test Nullable Unique Default Value Foreign Key Cascading Update Default Delete Constraints

  32. The Rollback Pattern rollback Service Write Test Known State

  33. Performance Patterns • The Performance-Test Pattern

  34. The Performance-Test Pattern Pass Code Metric At Start Metric At End Pass criteria Fail

  35. Simulation patterns • Mock-Object Pattern • The Service-Simulation Pattern • The Component-Simulation Pattern

  36. Mock-Object Pattern Abstract Methods Mock Object Implementation Real Access Layer Implementation Instantiates one of Factory Mode

  37. The Service-Simulation Pattern Simulated Service I/O Test Test Code

  38. The Component-Simulation Pattern Component Failure Timeout Recovery Code Test

  39. Stress test patterns • The Bulk-Data-Stress-Test Pattern • The Resource-Stress-Test Pattern • The Loading-Test Pattern

  40. The Bulk-Data-Stress-Test Pattern Pass Bulk Data Performance Metric Data Process Data Manipulation Fail

  41. The Resource-Stress-Test Pattern Code Test Set Resource

  42. The Loading-Test Pattern Code Test Loading

  43. Useful links Extreme Programmingwww.extremeprogramming.org XP Programmingwww.xprogramming.com Unit Test Patternswww.codeproject.com/gen/design/autp5.asp Continuous Integration www.martinfowler.com/articles/continuousIntegration.html Darrell Norton’s Blogwww.codebetter.com/blogs/darrell.norton/articles/50337.aspx

  44. Q & A Q & A

More Related