Home Coding Wiki
RSS
 

Posts Tagged ‘junit’

Combining JUnit Theories/Parameterized tests with Spring

07 Jul

In almost any project that is using Spring, you get to the point where the Spring’s dependency injection mechanism is required also for unit tests. Combining this with JUnit leads one to the usage of the SpringJUnit4Runner to enable the initialization of the Spring context, as well as the autowiring of various beans in the test object that is just being executed.

However, for more specialized unit testing purposes, such as implementing parameterized tests or theories, one must use a specialized runner (Parameterized and Theories, respectively). This, of course, gets in conflict with Spring, which needs to use it’s own runner. JUnit does not support multiple runners for the same unit test (and except for the Spring runner, all the other runners are pretty excluding one another so it kind of makes sense to allow only one runner at a time). Read the rest of this entry »

 
8 Comments

Posted in Spring

 

Unit testing guidelines

19 Sep

While developing a product, an important part of the development process is writing unit tests. These (in most cases, small) units of code create the safe net that will protect you when making changes, refactoring code or implementing new features. Since we are humans, and prone to mistake, we need at least this kind of system to make sure that the changes that we just performed do not brake the system, and do not have unknown or hidden side effects in the other components of the product under development.

Therefore, here are some of the guidelines and practices that I found very useful when writing unit tests (in my examples, I will use JUnit, but the these guidelines stand up for any other unit testing framework): Read the rest of this entry »