{"id":949,"date":"2014-03-18T11:31:18","date_gmt":"2014-03-18T18:31:18","guid":{"rendered":"http:\/\/10kdev.net\/?p=949"},"modified":"2014-03-19T10:12:10","modified_gmt":"2014-03-19T17:12:10","slug":"debugging-tests-with-eclipse-and-maven","status":"publish","type":"post","link":"http:\/\/10kdev.net\/?p=949","title":{"rendered":"Debugging Tests With Eclipse and Maven"},"content":{"rendered":"<p>Here are two techniques for debugging tests for Java Maven applications running Tomcat as you work in Eclipse. \u00a0There&#8217;s usually a problem with having two processes running &#8212; your test and then your production code (Tomcat) in two different processes.<\/p>\n<p>These tests are integration style tests that run code against something running in a Tomcat container that is started by Maven (along with a database). \u00a0 Throw your breakpoints in your test code AND your production code. \u00a0Also, during the debug process you might have to attach your source code for your production code; it&#8217;s not difficult. \u00a0You might have to restart the test after that . . .<\/p>\n<p><strong>Method One &#8212; Everything in One Process<\/strong><\/p>\n<p>You can run everything with a Maven configuration in eclipse, but it takes a bit longer for it to run. Setup a new Debug Configuration&#8211;&gt;Maven Build in Eclipse. \u00a0Mess around with the setup, but this works for me:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/80757608a2ed08bfe1e1dc1943d2fb87.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/80757608a2ed08bfe1e1dc1943d2fb87.png\" width=\"545\" height=\"319\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Notice in the goals I have<\/p>\n<pre style=\"padding-left: 30px;\">-Dtest=IntegrationTest_1_Test -DfailIfNoTests=false clean install<\/pre>\n<p>If you have a more complex parent\/submodule Maven pom setup like I do, you&#8217;ll need the failIfNoTests so that the entire thing can build before Tomcat kicks off. (Also depends on your project setup in the pom).<\/p>\n<p><strong>Method Two &#8212; Remote Process<\/strong><\/p>\n<p>This method has a few steps but works a bit faster.<\/p>\n<p>1. \u00a0Start up your maven tomcat process in DEBUG mode from a command line. \u00a0 You used to have to set a bunch of MAVEN_OPTS (and still can), but i Maven 3.0.5 and higher you can do this easily with a default port of 8000 by running <em><strong>mvnDebug<\/strong> <\/em>instead of mvn:<\/p>\n<pre style=\"padding-left: 30px;\">start mvnDebug compile tomcat7:run<\/pre>\n<p>You get something like this as it waits:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/7753af05a9bd92043f84020683cafac3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/7753af05a9bd92043f84020683cafac3.png\" width=\"434\" height=\"89\" \/><\/a><\/p>\n<p>2. \u00a0Create a DEBUG configuration for the remote port in Eclipse with port 8000, then start it with the <strong><em>Debug<\/em> <\/strong>button:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/442408bc61bd72dedde253c54a604987.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/442408bc61bd72dedde253c54a604987.png\" width=\"547\" height=\"320\" \/><\/a><\/p>\n<p>3. \u00a0Run your test like you would in the IDE normally &#8212; no need to run it via Maven. \u00a0If you Debug your test &#8212; then you can throw breakpoints in the test and the code running in Tomcat. \u00a0If you just Run your test you will only hit the Tomcat breakpoints.<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/151dc9df517ec0225343d907e6821b58.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter\" alt=\"\" src=\"http:\/\/10kdev.net\/wp-content\/uploads\/2014\/03\/151dc9df517ec0225343d907e6821b58.png\" width=\"494\" height=\"184\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are two techniques for debugging tests for Java Maven applications running Tomcat as you work in Eclipse. \u00a0There&#8217;s usually a problem with having two processes running &#8212; your test and then your production code (Tomcat) in two different processes. These tests are integration style tests that run code against something running in a Tomcat [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/949"}],"collection":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=949"}],"version-history":[{"count":8,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/949\/revisions"}],"predecessor-version":[{"id":957,"href":"http:\/\/10kdev.net\/index.php?rest_route=\/wp\/v2\/posts\/949\/revisions\/957"}],"wp:attachment":[{"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=949"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/10kdev.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}