Showing posts with label Junit. Show all posts
Showing posts with label Junit. Show all posts

Saturday, April 09, 2011

Q : How do you Unit Test private methods using JUnit

Soln1: http://sourceforge.net/projects/junit-addons
Look at that. It has a PrivateAccessor class to call private methods and fields. It also has utility classes for array comparision and the likes. I really like it.

Soln2: Make it non-private. Or for every private foo(), add another method foo_FOR_TESTING_ONLY() that calls foo(). Or zap the class with reflection to make the method non-private temporarily.

Tuesday, January 18, 2011

Junit 4.0 & TestNG Quick Comparison

JUNIT 4.0

  • Fixtures – should be static in Junit
  • Dependency Testing – Testing Isolation is a strong point, but neglects dependency testing
  • + Test result Turnaround and cycle wastage
  • Focus on Unit Testing of Objects
  • Test Code and Test Data separation is hard, might need to use FIT

TEST NG

No Fixtures – no Static required

  • Dependency Testing - @Test (dependsOnMethods = {"verifyLogIn"}) / but still the scope is single Test class / The test dependency is still within a test class.
  • Time Saved in Test Re-Run ( by generating xml of only failed test cases )
  • * Focus on higher level,
  • EASY Test Code and Test Data Separation, by TestNG's XML configuration
  • Complex Data can be fed to the test by using @DataProvider annotation, which facilitates the mapping of complex parameter types to a test method.