Utilizing a debugger when developing Unit Tests for ONAP can be useful. The problem is that normal execution using the Maven Surefire plugin runs in its own JVM. Furthermore, default execution of the test goal results in all tests being run. I found some handy tips for using the Eclipse debugger and isolating particular tests.
- From the command line, invoke mvn test goal but specify the flag to enable remote debugging
mvn -Dmaven.surefire.debug test
The execution will stop with a message like:
T E S T S
Listening for transport dt_socket at address: 5005
- Configure a remote debug job in Eclipse. There are probably many ways to do this, but I opened Debug Configurations, selected "Remote Java Applications", filled in Name: "remote debug on 5005", Host: localhost, Port: 5005. This step only needs to be done once.
- Set breakpoints of interest, and launch remote debugger created in step 3.
To just run a single test class instead of the whole works, start maven using the -Dtest param. For example,to only run tests defined in test Class DmaapResourceTest.java:
mvn -Dtest=DmaapResourceTest -Dmaven.surefire.debug test
- I was running on an Ubuntu 16.04 VM instantiated on Oracle VM VirtualBox Manager running on Windows 10, and did experience a problem stepping through some functions. In Eclipse, I disabled Preferences->Java→"Show method result after a step operation (if supported by the VM; may be slow)" which I found in an unrated answer in Ref 3 above.