Skip to main content

Posts

Showing posts from October, 2010

Simpler parameterization of Junit tests

Why write a custom runner/suite? Usually Junit's default suite/runner combined with parameterized.class are great for parameterizing your tests. But the need to provide a specifically written constructor, and the need to add a specifically annotated and written method to your test class is rather annoying. The Collection syntax is also weird, though generic. To hide the details of parameterization, and provide such support simply through the use of @RunWith is what I am after. It is okay if my class has to implement another interface, but I would look to minimize impact on the user test class and coupling between test class and test infrastructure. It is good that JUnit 4 has made it easier to write your own custom Suites and Runners. How do suites and runners work? In brief, a Junit Suite wraps around your test class and create a test 'runner' for your class. A Suite can contain one or more test classes, but for design ease, I will always assume one suite contains on