4

I have writting some JUnit integration tests that currently run from Maven (via the command line or out CI server). These integration tests automatically configure and startup the database and servlet container inside of Maven's 'pre-integration-test' lifecycle phase.

I would very much like to run these JUnit tests (like I do all our other tests) from within an Eclipse JUnit launch configuration. However, the JUnit launch configuration does not trigger the pre-integration-test executions and thus the environment to test is not properly established.

Whats the best way to get this to work?

4

4 回答 4

3

You can setup Maven Run Configurations to run within Eclipse, using Run -> Run Configurations, assuming you have the Maven plugin for Eclipse. Using the goals clean verify will run unit tests and integration tests.

Also if you use the failsafe reports Maven plugin, you can create JUnit style reports, that you can open in Eclipse using the JUnit framework, to see which tests passed and failed.

于 2013-04-15T14:48:50.847 回答
2

One way to do this I just discovered is to use Eclipse Launch Groups as shown here:

http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.cdt.debug.application.doc%2Freference%2Fcdt_u_run_dbg_launch_group.htm

I missed this because this capability, while language independent needs to be installed from the C/C++ side of Eclipse as shown here:

What installable component provides 'launch groups' in Eclipse?

Within the launch group the first job should run a maven task to process test resources, the next jobs launch the server(s), and then finally a job to execute the junit tests.

于 2016-05-10T21:09:01.110 回答
0

I don't know what database you want to use, but for unit tests its handy to use an in memory database and maybe also an embedded servlet container. Maybe you could use something like http://arquillian.org/

于 2013-04-15T14:28:28.523 回答
-3

JUnit framework should be mainly used for Unit testing and not Integration testing. Integration testing could be performed by QA team.

If you have lot of Integration plumbing code then you should considering Mocking of external elements, such as Databases and web services calls.

Concentrate mainly on testing code that you have written.Add negative, positive and exceptional test scenarios. That will give your code more credibility than full integration test.

For Database I suggest using DBUNIT > http://www.dbunit.org/ which is an excellent tool for testing database plumbing. This tool can create XML schema from your database and you can keep data as xml replicating the database. This will avoid changing any dataset for your JUnit testing.

于 2013-04-15T15:00:02.817 回答