using command line how run junit test present inside the war file

1.8k views Asked by At

using maven we create a war file and we need to be deployed this war in tomcat(application server) for different environment (DEV/QA/UAT). We need to run the JUNIT test for each of the environment before deploying. we have written nearly 60 junit test which need to passed
Is is possible to run the junit test for war file?
if yes how to run all junit test sitting inside the war file

1

There are 1 answers

0
luboskrnac On

WAR file is deployment artifact that shouldn't include any unit tests. As @Gerold Broser correctly pointed out, Maven handles excluding of unit tests for you if you place them into "src/test/java". Don't ever try to put them into "src/main/java".

we have written nearly 60 junit test which need to passed Is is possible to run the junit test for war file?

If they are true unit tests, they don't need to be executed against deployed war service. They are testing small chunks of functionality and are generally executed during test phase of maven lifecycle.

If tests are firing requests against deployed server, at that stage they are not unit tests anymore and should be probably placed into separate test project.

Proper place where to run your tests is always Continuous Integration server, so one way or the other make sure that execution is automated! Tests without CI server are waste of time.

BTW There is maven-tomcat7-plugin to start tomcat and deploy it during interation-test phase of Maven lifecycle, but this maven plugin doesn't seem to be maintained anymore and doesn't work with Servlet 3.0 Java configs and Tomcat 8. So I don't recommend that path.