Java – how does eclipse actually run JUnit tests?
I encountered a difference when running JUnit tests in eclipse and ant This is the scenario:
Everything runs as expected in eclipse, but when I run through my ant build script, I can't get an accurate JUnit report I made some changes to our test runner and test cases (in short, I added the test suite () method to all my test cases), which returned a new junit4testadapter and let our custom runner execute runnotifier Firetest estimation failed (failure) instead of firetest estimation Everything in ant is now working properly, but when running in eclipse, the fault is marked as passed
Is there any eclipse documentation that explains exactly how it runs JUnit tests? I basically want to know how eclipse executes JUnit test, whether it runs directly through ant, if it uses Java and JUnit interface, etc If someone knows the practical solution to this problem, I also welcome it, but I will. I really want to try to solve this problem myself. I just need a right direction
Solution
To answer your question first, if you have a difference between ant JUnit and eclipse JUnit, it may be a classpath or environment problem The easiest way to do this is to find a way to run different tests between them and print out the system properties, and start working in that direction Another thing to try is to run ant scripts from eclipse to see if there is any difference (because the environment changes)
Eclipse does not use ant to run tests
Here is a quick overview of how eclipse runs JUnit tests Please note that there is some deep magic in the eclipse JUnit plug-in
Eclipse has four JUnit plug-ins, which are installed in most configurations by default:
> org. eclipse. jdt. junit:git://dev.eclipse. org/org. eclipse. jdt/org. eclipse. jdt. junit. git > org. eclipse. jdt. junit. core: git://dev.eclipse.org/org.eclipse.jdt/org.eclipse.jdt.junit.core.git > org. eclipse. jdt. junit. runtime: git://dev.eclipse.org/org.eclipse.jdt/org.eclipse.jdt.junit.runtime.git > org. eclipse. jdt. junit4. runtime: git://dev.eclipse.org/org.eclipse.jdt/org.eclipse.jdt.junit4.runtime.git
These are git images of the actual CVS repository The last time I tried to use them, they didn't compile, but they will give you code. At least you can import the project into eclipse and view them
If we ignore the configuration page, how the plug-in creates and runs the configuration, the code of the JUnit view itself and how it finds the relevant tests to run, we can focus on how it runs the tests
The core class is org eclipse. jdt. junit. launcher. Junitlaunchconfigurationdelegate and org eclipse. jdt. internal. junit. runner. RemoteTestRunner. Junitlaunchconfigurationdelegate reads the startup configuration and forks out the JVM that will run the test The main class of this new JVM is remotetesrunner The test to run is passed as a parameter to the forked JVM, as a single test or as a test list in a temporary file, if you execute run as JUnit on the project If you are debugging, you can keep this new JVM active by selecting the "keep active while debugging" check box in the run configuration In this case, the JVM will remain unchanged and the rerun of the existing test will be sent through the socket
The remote test runner runs the test and sends the results back to eclipse through a socket, and then eclipse updates the JUnit view Its core is org eclipse. jdt. internal. junit4. runner. Junit4testreference, which runs tests (for JUnit 4), and org eclipse. jdt. internal. junit4. runner. Junit4testlistener, which is the runlistener of these Test Junit4testlistener extends runlistener, but does not cover testassumptionfailure, which may be the reason why your tests are passed in eclipse RunListener. Testassumptionfailure is an empty method that does nothing, so your notification will be ignored
I will first clone git repos, import the project into eclipse and try to complete the code