Reputation: 5448
We have for all our tests a method which starts a Jetty Server to publish and test the Web-Services:
@Before
public void startJettyAndloadWSDL() throws Exception {
String port = System.getProperty("jetty.port");
server = new Server(Integer.valueOf(port));
WebAppContext webapp = new WebAppContext();
webapp.setSecurityHandler(getSecurityHandler()); // this is a local function in my test
webapp.setContextPath("/");
webapp.setWar(System.getProperty("jetty.war"));
server.setHandler(webapp);
// Is there an option somewhere to say "start Jetty in Debug mode"?
server.start();
service = new MyServiceToTest(new URL("http://127.0.0.1:" + port + "/WS/MyServiceToTest/1?WSDL"),
new QName("urn:myservicetotest.services.mycompany.com/1", "MyService")).getMyServicePort();
}
Is there any way to say Jetty to start in Debug Mode in order to put a breakpoint in Eclipse?
The test is run using Maven externally to Eclipse, then perhaps it is better to make a remote debugging in that case? We do not want to have a big link with Eclipse, then it is why we start the jetty in all JUnits tests.
Upvotes: 0
Views: 3136
Reputation: 5448
We cannot change the embedded Jetty because the continous integration needs it and we will not maintain two version of the JUnit tests (automated or manual).
The solutions I found are:
1 - From maven with remote debug:
Start the test with the following commmand (from maven site):
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test
and then start the Eclipse remote debug on port 8000. But this solution is not very clever: as the jetty is embedded, I have to manually start the remote debugging of Eclipse and it needs some synchronisation when I start maven from the command line (maven is not integrated to eclipse in that project).
The best way we finally use is:
2 - From Eclipse Junit
I just execute the Junit Test from Eclipse in debug mode and this is just perfect: the jetty startup method does not need any option for debug mode
as it is the JVM which starts in runtime or debug mode.
I do not need to use the WTP jetty in the Eclipse, I just had to define the properties in the test like:
${jetty.port}
and the breakpoint stops where I want.
The only configuration is in Eclipse and it will not change our code.
Upvotes: 2
Reputation: 22446
There are generally two contexts where tests are run 1) as part of a build to ensure that the new build doesn't fail any tests, and 2) when developing to ensure that a small piece of functionality works before moving forward.
I think the issue here is that, by having your tests start Jetty, your environment is trying to handle both of those scenarios at the same time and I'm not sure that that's possible in a clean way.
I think you'll want to remove the jetty start from your test code and, to handle context #1, let maven start Jetty in the pre-integration-test phase, and run tests that require jetty in the integration-test phase. This is a very common way of running tests that require a web server.
When operating in context #2, start an embedded Jetty in Eclipse in debug mode, and then run your test from Eclipse instead of from Maven.
Upvotes: 1