Generate JUnit Test report - eclipse

Is it possible to have JUnit Test report data in html in eclipse(kepler), which show many test case and how many passed, what is the intent of test cases etc.

Yes it can be done using Ant eclipse build file read more here the Ant build file generated from eclipse it self.
More References :
1)http://www.java2s.com/Code/Java/Ant/Junitreport.htm
2)http://earlwillis.wordpress.com/2012/01/31/getting-started-with-junit-reports/
3)http://ant.apache.org/manual/Tasks/junitreport.html
Hope that helps

Related

My jar won't add my junit tests

The contents of my jar file does not contain my junit tests. I tried creating a main class that calls my tests with "Junit Core" but that too doesn't get added to my jar file. What am I missing?
Your production package (your jar) is not supposed to contain the test code (your unit tests).
Test code is supposed to be invoked only when the tests are been executed.
You shouldn't do it, but if you want the test code to be included in your package just put it in the same root folder of your production code. Ex: if you are using Maven, your folders structure might be something like this:
project_name/src/main/java/
-> production code
project_name/src/test/java/
-> test code
In that case, change it to:
project_name/src/main/java/
-> production code
-> test code
Be aware that doing that you will have some problems, like the tests not executing during a normal build. We might help you better if you put a question asking how to accomplish your goal (what is your goal?).
Update based on the goal explained in the comments: Would be better if this tool (Silk Central) could run your tests using Maven or Ant, and I'm pretty sure it can.
I've been used different tools to run my Junit (or other XUnit frameworks) tests. What I do is to configure the tool to:
Get the source code from the version control.
Run the build/tests by calling Maven or Ant installed along the tool.
Read the Junit outputs.
Sometimes the tool has its own integration with Junit and you don't have even to use Maven or Ant.
I mean, your central build or tests tool should be able to run your tests just like you do in your own machine.
Take a look on this or search by "Silk Central junit" in the web:
http://community.microfocus.com/borland/test/silk_central/w/wiki/465.zero-maintenance-junit-testing-using-classpathsuite-in-sctm.aspx

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?.

How to do a clean build in eclipse and run a junit test case at startup?

Is there any way we can clean all/rebuild the projects in eclipse and run a jUnit test case every time we open eclipse?
I am developing an eclipse application. The scenario is that i want to schedule UI tests to happen automatically twice everyday. But i do not have an executable build as such. But have the full code base with me and i want to run some scheduled JUnit test cases(based on WindowTester) on it.
Any other ideas that you have is also welcome. :) Thanks in advance.
Ant requires a executable build to perform the tests on it from what i have read. :(
Regards,
Thomas
Tough Jenkins is opensource, Going for jenkins will be a good choice if you have more number of projects to manage. Jenkins dose lot more than automated test case and builds.
But, If you have a small code base and need to peform some specific tasks like
scheduled build and test cases, ant build will is much preferable.
In your case for running test cases,
Create a ant build script to build the entire project (How to write Sample Build scprit)
Create another ant script to read the jars and execute them using the tag (How to write Sample Test Build)
Write a bat file to call the ant scripts and Schedule build twice a day in windows scheduler available in control panel.
SO, this will compile, build your project and test it in scheduled time. Just trigger a mail from the ant script if test fails.

Beginner: How to do JUnit tests on GWT application?

I want to preform a JUnit tests on my application. I've never done JUnit testing before so I have a couple of (maybe trivial) questions:
Where should I put a test class? I came across with this thread:
Where should I put my JUnit tests?,
and the guy that answers the question is referring to maven projects, but I don't use maven. He explains (in the thread I linked above) that he puts the test class in a different location but in the same package. How can it be done in a GWT project?
How should I execute these tests once they are ready (where in the code to put the execution)?
You should begin by reviewing this: Unit Testing GWT Applications with JUnit.
The other thread is good and reflects the typical JUnit practice, and isn't specific to maven: use a mirror of your package tree under a directory called test. So for instance if your GWT EntryPoint module is located in this directory structure:
project/src/com/myproject/mypackage/MyEntryPoint.java
Then your test code will be here:
project/test/com/myproject/mypackage/MyEntryPointTests.java
If you've created your GWT project using webAppCreator then you should already have a test directory containing the package structure as described.
If you use webAppCreator to create your project, the project can be created with unit testing built-in like so:
webAppCreator -junit -out MyProject com.myproject.mypackage.MyEntryPoint
This will create a test target. If you're using Eclipse, then you should have a Run selection for: Run As -> GWT Unit Test for running your tests.
If you're using ant instead of Eclipse then this should run your unit tests:
ant test
If you didn't use -junit to create the project, the test targets are typically still there, just commented out. Search junit in build.xml to find the targets, and un-comment them.
You need to take a look at this article, MVP1 and MVP2, these are a pattern designs used to Unit Test your application in pure java environment, because using GWT Test Case runs very slow the patterns also has many advantages like separate the logic from the view so you can change the view for Android, for example.

Running JUnit through 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