views:

29

answers:

1

I'd like a junit runner that executes all @Before methods, then all @Test methods, then all @After methods.

This is how my System-Tests work. The @Before methods are run, to setup the test data and scenarios. The application is started. Then the @Test methods are run with the application running in the background. Those @Test methods can change data or respond to the application. Then the framework waits for the application to finish up. Afterward, the @After methods are run to verify the test results.

I already use junit annotations, assertion methods, and other various bits. But I just can't figure out how to use junits runners to execute test methods in this way. I couldn't make heads nor tails of the "Computer" interface in junit 4.8, or figure out how to apply Rules to this.

+1  A: 

This isn't what JUnit does. JUnit has a design philosophy that emphasizes independent unit tests. As such, it isn't a natural framework for system tests. What you want to do fits nicely into TestNG (which as a design goal tries to straddle both unit and system tests).

In JUnit the @Before and @After are run before and after each test. You can shoehorn this kind of thing into JUnit using a Suite, which references all of your tests and is responsible for all setup and teardown, so the Suite's @BeforeClass and @AfterClass methods get run before and after the suite, which if you organize it correctly could be all of your system tests.

There are lot of organizational challenges in the code when it gets large with the JUnit approach, so I would suggest you consider and alternative framework if this is the bulk of what you want to do.

Yishai
Good point, I've left the realm of junit. Its time to admit it to myself, and move on. (for my non-unit tests at least).
DragonFax