TestNG unit test at maven install, install ->deploy to jetty ->start jetty ->run test -> stop server

StackOverflow https://stackoverflow.com/questions/8557420

Question

I have a maven project.

I want to test (spring) controller class and also wrote a test class.To successfully run this test class,I want the web app to be deployed in the (jetty )server.

How I can achieve this, when I execute maven clean install.project is

    built->deployed to server->start server->run test->stop server

I have been looking at jetty plugin and cargo plugin but still finding it difficult to do what I want.

Was it helpful?

Solution

If you want to unit test your spring controllers, you do not need to have your web application deployed to jetty. Spring framework has testing support as documented here.

There are many examples in the web. You can also refer to the test classes here which uses testNG.

If you do want to run tests in jetty, then refer to these instructions. Essentially you would bind the jetty start and stop to pre-integration-test and post-integration-test phases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top