Alex Rivera | Logout

JUnit 4: Set up things in a test suite before tests are run (like a test's @BeforeClass method, just for a test suite)

Asked 2008-12-08T15:23:00.573
25

I want to do some functional testing on a (restful) webservice. The testsuite contains a bunch of test cases, each of which performs a couple of HTTP requests on the webservice.

Naturally, the webservice has to run or the tests will fail. :-)

Starting the webservice takes a couple of minutes (it does some heavy data lifting), so I want to start it as infrequently as possible (at least all test cases that only GET resources from the service could share one).

So is there a way to do set up me the bomb in a test suite, before the tests are run like in a @BeforeClass method of a test case?

Edit
Report

1 Answer

-3

As an aside, it's a bad idea to have unit tests actually calling external resources like webservices, databases, etc.

Unit tests should be super-quick to run and a delay of 'a couple of minutes' for each run of the suite will mean it won't be run as much as it should.

My advice:

Look at mocking external dependencies in unit tests with something like EasyMock (http://www.easymock.org/).

Build a seperate suite of integration tests with something like Fitnesse (http://fitnesse.org/) or a homegrown solution that runs against a test environment and which is continually up.

answered 2008-12-09T11:52:46.723

Your Answer