Running JUnit through Eclipse - eclipse

I run my JUnit tests through Eclipse (Helios, 1.3.0) through an ant build file and an external ant builder. I was wondering if it's possible to use Eclipes's JUnit UI when running them so that I can see the 'green' or 'red' bar in there instead of seeing success/failure messages in the console. Any pointers are greatly appreciated. Thanks!

If you must run your tests via ant, then there is no direct way to see the progress in the JUnit view. However, if you are using the JUnit ant task and set the output format of your test results to xml :
Then, you can open this file up in the JUnit window. Click on the button on the far right and select Import. Then navigate to the file you want to open:

If you have JUnit reference for a project, I think you can right click on a project and select Run As > JUnit Test and that will run all the tests in the Project. Check out this post

Eclipse: Writing and running JUnit tests

Related

Netbeans 12 and TestNG with parallel tests

i'm using apache NB 12.2
I would like to use TestNG to do parallel tests, but NB it does not recognize the testng.xml file on which I indicated the tests to be done in parallel
this is the picture of NB: https://ibb.co/80Yj5jL
here I uploaded the entire project folder NB: https://wetransfer.com/downloads/9c8f21d863cd0af9e282fd1e615789e320210113182454/4d212bc4810913e630c33fc67344cc9b20210113182532/c08ff0
I did several tests, but in fact, it does not find the testng.xml file
Thanks!
Roberto.
the solution is trivial .. to run suite test simply click on the testng.xml file with the right mouse button and choose "test" ..

How to save the test result of Junit with Eclipse?

i'm trying to get the result of jUnit test with Eclipse in a separate file as txt file.
What should i add in the java unit code?
I was trying with build.xml but i have the following error :
build.xml:100: java.lang.NoClassDefFoundError: org/apache/xml/serializer/ExtendedContentHandler
I tried to resolve this by adding Junit.jar but still i have the same error.
So that's i want to try to get the result in a file.
Thank you
In the top right corner of the Junit test runner, you can see a dropdown. Click that and you will find an option to export. Export the test result to the desired location. You will get the XML format of the test report in the provided location.
Generate Ant build file for your project and use Ant to generate junit reports. Refer this.
Also check this post How can I generate an HTML report for Junit results?.

Show Jenkins test results in Eclipse JUnit view

Is there a way to import the Jenkins JUnit test results into Eclipse's JUnit view? I found the 'Import from URL...' in Eclipse. Is there a way in Jenkins to create the necessary XML file?
I guess what I really wanted is provided by the Mylyn's Hudson/Jenkins connector.
Install it using Install new features... in Eclipse using the Mylyn's update site
for Eclipse Juno: http://download.eclipse.org/mylyn/releases/juno
for Eclipse Kepler: http://download.eclipse.org/mylyn/releases/kepler
and tick the appropriate Mylyn build connector.
Once installed open the appropriate view using Window > Show View > Others and selecting Mylyn > Builds
Work's like a charm! You can monitor and start Hudson/Jenkins builds, and view the build console and JUnit results directly in Eclipse!
You can get the latest test result file directly from workspace folder (You could look your last build file in /jenkins/jobs/XXXXXXX/builds/YYY to know where it lies).
But for previous builds I'm afraid Jenkins keeps its own file with its own structure under /jenkins/jobs/XXXXXXX/builds/YYY.
So unless you have a task copying the result for you somewhere, I don't think you'll be able to import them in eclipse.
I am sure that using ANT Junit reports can be created with Jenkins. That XML file can then be taken as URL then.
In addition to the usage of the Mylyn connector, in Jenkins one needs to specify "Publish JUnit test result report" in the "Post-build Actions" section of the project's configuration page. The parameter is the pattern for the xml files of the tests results, or pattern for the xml file of the JUnitReport task if it is used.
That was the thing that worked for me. I Don't know if that option had existed back then though.

m2eclipse filtering test resources

I am using m2eclipse and I want to right click and run tests from inside eclipse while the test resources get filtered from Maven. How can I do this? From eclipse when I right click on a test I do not get any m2eclipse options
Julia.
Similar to:
Debugging maven junit tests with filtered resources?
Setup filtering in your pom.xml (and you'll get filtering under Eclipse with m2eclipse, m2eclipse runs process-resources after a change of any resource).
Run your test as any other test (right-click then Run As > JUnit Test).
After a first run, you can run an individual test method (right-click on the method in the JUnit view).
Right click on the project -> Run As -> Maven test

How do I configure Eclipse to run your tests automatically?

I read this article: Configure your IDE to run your tests automatically
http://eclipse.dzone.com/videos/configure-your-ide-run-your
It's pretty easy to configure Eclipse IDE to run an Ant target every time a file is saved.
MyProject -> Right-click : Properties -> Builders -> New -> Ant Builder
The problem is that the builder has to rebuild the jar on every save, which is very long. The JUnit tests run using the .classes in the jar.
We already have JUnit configurations (EclipseIde .launch files which contains the whole classpath to run the tests). I wish I could create a builder that wraps those JUnit launch files. This would have the benefit of running the tests against Eclipse .classes (faster than rebuilding the jar). Also the test results are displayed in the JUnit view.
Has anybody manage to do that?
I recently started using Infinitest and it seems to somehow "know" which parts of the code affect which test cases. So when you change some code, it automatically re-runs the tests which are likely to break. If the test fails, it marks an error at the spot where it failed, the same way Eclipse would mark a coding error like calling a non-existent method or whatever. And it all happens in the background without you having to do anything.
You could try CT-Eclipse, a continuous testing plugin for Eclipse.
From the plugin page:
With CT-Eclipse enabled, as you edit your code, Eclipse runs your tests quietly in the background, and notifies you if any of them fail or cause errors.
You can use JUnit Max it is an eclipse plug in that will run all you tests every time you save. But it will do it without interrupting your work flow. The results are shown in the left corner of Eclipse and you can always go back to the last successful testrun. The plugin runs the tests that are most likely to fail first so that you get a response for your last saving as fast as possible.
http://www.junitloop.org/index.php/JUnitLoop is another one like this (haven't tried it yet myself)