Generation_P Consulting LtdSoftware Solutions for the Travel Industry               TDD        Make your life better      ...
TDD: way to better life Test before code! TDD principals:    think first    trivial first    test <=> what ; implementat...
TDD: Pair programming    ping – pong    who has keyboard is a King!    through-test driving
TDD: Testing best practices
TDD: Test naming
TDD: Test naming
TDD: Exception processing
TDD: given-when-then
TDD: multiple asserts
TDD: Whole test system     manual    auto gui  acceptance integrationunit tests
TDD: Unit tests    One test – one behavior    Independent: isolated class    Reliable    Fast
TDD: Integration and Acceptance Tests          integration: component               communication with some          isol...
TDD: Mocks    fake – some little implementation    stub – return some predefined result    mock – object with programmed...
TDD: Mockito Easy to:     stub methods     verify behavior     verify sequence of calls Cannot:    mock final classes,...
TDD: Mockito   @RunWith(MockitoJUnitRunner.class) annotation at    the class-level of the test case   @Mock annotation a...
TDD: Mockito
TDD: PowerMock Easy way to mock:     static methods     final methods or classes     private methods     construction o...
TDD: PowerMock      @RunWith(PowerMockRunner.class) annotation at the class-level of the test case.      @PrepareForTest...
What to read?    Robert C. Martin “Clean Code: A Handbook    of Agile Software Craftsmanship”    Joshua Kerievsky “Refact...
Questions?Thank you and good luck!
References   http://www.slideshare.net/agileee/clean-    tests   http://www.slideshare.net/wakaleo/junit-    kung-fu-get...
Upcoming SlideShare
Loading in …5
×

Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская

883 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
883
On SlideShare
0
From Embeds
0
Number of Embeds
166
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • 28.01.2012
  • Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская

    1. 1. Generation_P Consulting LtdSoftware Solutions for the Travel Industry TDD Make your life better Antanina Shafranskaya Antanina.Shafranskaya@generation_p.com
    2. 2. TDD: way to better life Test before code! TDD principals: think first trivial first test <=> what ; implementation <=> how different levels of tests red – green – refactor red: behavior (responsibility oriented design) green: coding refactor: design, refactor
    3. 3. TDD: Pair programming ping – pong who has keyboard is a King! through-test driving
    4. 4. TDD: Testing best practices
    5. 5. TDD: Test naming
    6. 6. TDD: Test naming
    7. 7. TDD: Exception processing
    8. 8. TDD: given-when-then
    9. 9. TDD: multiple asserts
    10. 10. TDD: Whole test system manual auto gui acceptance integrationunit tests
    11. 11. TDD: Unit tests One test – one behavior Independent: isolated class Reliable Fast
    12. 12. TDD: Integration and Acceptance Tests integration: component  communication with some isolation acceptance: full system test, no  isolation or mocks client requirements 
    13. 13. TDD: Mocks fake – some little implementation stub – return some predefined result mock – object with programmed expectation spy – stub with flow verification
    14. 14. TDD: Mockito Easy to: stub methods verify behavior verify sequence of calls Cannot: mock final classes, methods mock static
    15. 15. TDD: Mockito @RunWith(MockitoJUnitRunner.class) annotation at the class-level of the test case @Mock annotation at mocking objects init tested class in method annotated with @Before when(mock.methodCall()).thenReturn(someResult); doThrow(exception).when(object).voidMethodCall(); verify(mock, times).methodCall() verifyZeroInteractions(mocks) inOrder(mock)
    16. 16. TDD: Mockito
    17. 17. TDD: PowerMock Easy way to mock: static methods final methods or classes private methods construction of new objects partial mocking
    18. 18. TDD: PowerMock @RunWith(PowerMockRunner.class) annotation at the class-level of the test case. @PrepareForTest(ClassThatContainsStaticMethod.class) annotation at the class-level of the test case. PowerMock.mockStatic(ClassThatContainsStaticMethod.class) to mock all methods of this class. PowerMock.mockStaticPartial(ClassThatContainsStaticMethod.class, "methodName", ArgumentClass.class); PowerMock.replay(ClassThatContainsStaticMethod.class) to change the class to replay mode. PowerMock.verify(ClassThatContainsStaticMethod.class) to change the class to verify mode.example: http://code.google.com/p/powermock/source/browse/trunk/modules/module- test/easymock/junit4- test/src/test/java/samples/junit4/singleton/MockStaticTest.java
    19. 19. What to read? Robert C. Martin “Clean Code: A Handbook of Agile Software Craftsmanship” Joshua Kerievsky “Refactoring to Patterns” Steve Freeman, Nat Pryce “Growing Object- Oriented Software, Guided by Tests”
    20. 20. Questions?Thank you and good luck!
    21. 21. References http://www.slideshare.net/agileee/clean- tests http://www.slideshare.net/wakaleo/junit- kung-fu-getting-more-out-of-your-unit- tests http://mockito.googlecode.com/svn/tags/ latest/javadoc/org/mockito/Mockito.html http://code.google.com/p/powermock/

    ×