Unit tests best practices

2,027 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,027
On SlideShare
0
From Embeds
0
Number of Embeds
1,053
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Unit tests best practices

  1. 1. Unit tests best practices<br />
  2. 2. 2<br />
  3. 3. Trustworsy<br />No logic in tests<br />Test one thing<br />Easy to run<br />Assure code coverage<br />3<br />
  4. 4. Maintenance<br />4<br />DRY<br />Tests isolation<br />One assert per test<br />Avoid over specification<br />Don’t call one test from another<br />Keep track on shared state (singletons, DB, file system)<br />AAA (Arrange, Act, Assert)<br />
  5. 5. Some patterns<br />Repository<br />A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. <br />Client objects construct query specifications declaratively and submit them to Repository for satisfaction. <br />Objects can be added to and removed from the Repository, as they can from a simple collection of objects.<br />5<br />
  6. 6. Some patterns<br />6<br />DAO<br />Access to data varies depending on the source of the data. <br />Access to persistent storage, such as to a database, varies greatly depending on the type of storage and the vendor implementation.<br />
  7. 7. DAO vs Repository<br />DAO<br />Repository<br />7<br />Full control over query<br />Easy to use<br />Unpredictable <br />Easy to mock<br />Generic<br />Linq provider <br />
  8. 8. Examples<br />Repository<br />Factories<br />Date time<br />Extension methods<br />Slide 8<br />
  9. 9. Contacts & Questions<br />Blog: http://slynetblog.blogspot.com<br />Twitter: @Kozhyn<br />Email: hedgic@gmail.com<br />9<br />

×