Re: JUnit-BDD
<[email protected]> 20 Apr 2014 06:17:58 -0700
| Newsgroups | gmane.comp.java.junit.user |
|---|---|
| Message-ID | <[email protected]> |
To be honest I think anotations give you nothing for free. The costs of annotations is: - You can't abstract over them (except the client of the annotations provides a custom way to do so) - Every Runner needs explicit support for each annotation, there is no way of supporting an annotation by doing nothing. - The whole JUnit Test discovery is based on reflection, which again means you can't properly abstract over it. To talk about a specific example: One of the things that is really annoying with JUnit is there is no nice way of have parameterized tests. Note I am aware of various attempts, but each is a) ugly b) needs a specialized runner and thus is more or less incompatible with other runners. So have fun to have Parameterized Test using the Spring Test Runner Now if registration of tests works through a simple method call instead of a method definition you can (among other things) just loop over it. Voila, parameterized tests solved. Without any special framework feature or addition. You want to do something before or after your tests? Just write your your own test registration method which wraps your lambda according to what ever needs you have. Done. Ooops, we just replaced the whole Rules stuff (which I love, but which is just a workaround). Jens PS: here are two articles doing this kind of stuff with scalatest. With Java 8 something similar should be possible. http://blog.schauderhaft.de/2011/08/28/manipulating-test-execution-with-scalatest/ http://blog.schauderhaft.de/2011/08/28/manipulating-test-execution-with-scalatest/ http://blog.schauderhaft.de/2011/01/16/more-on-testing-with-scalatest/ http://blog.schauderhaft.de/2011/01/16/more-on-testing-with-scalatest/