Running JUnit integration tests from a JSP? - junit

we need to do some integration testing of some Java classes which we want to run inside a Weblogic server. We have a JUnit test suite that runs a set of Junit test classes, and I would like to know if is a good idea to write a JSP that runs the test suite and prints out the results in a graphical way, in case we won't be able to access via SSH to the server and run the tests via console.
Step 1: We upload the jar file with the tests and the JSP
Step 2: We call the JSP via a browser
Step 3: Profit! Our tests are running and we have visual feedback.
Am I right or wrong? Thanks for your advices!

You should be able to use Cactus to do this,
See the following article for reference:
http://www.oracle.com/technetwork/articles/server-side-unit-tests-096611.html
That should save you having to write extra code, not sure about visual feedback but the Cactus page seems to suggest that when running in a servlet container like Tomcat you should get the results visually:
http://jakarta.apache.org/cactus/integration/howto_tomcat.html

Related

FitNesse: How to send tests execution reports from Jenkins to an endpoint in JSON format?

I have a task to send reports of periodic execution of FitNesse tests to some specific endpoint in some specific JSON format.
I set periodic execution of tests in Jenkins properties and saving it in XML, but now I need to parse information about results of it.
It cannot be just step in "after build" property in Jenkins (or can, but I don't know a plugin for it), but what it would be and how I can do this?
Especially, I don't need information about the test, only general moments like date of the test, pass rate, status, name of the project, etc.
I think the best way to solve this is to make a script that parses the XML file, and creates the required JSON file. We normally use python scripts for this.
If you need certain generic information of the build in the script, like build number, you can pass this to your script using the Jenkins environments.
To call the script just add a batch or shell step, and place it below your fitnesse build step, to make sure the XML is generated before calling the script.
FitNesse comes with a jUnit runner which allows you to execute a test/suite. If you create a test class annotated with #RunWith(FitNesseRunner.class) and include its execution in a Jenkins Maven job (where the jUnit class is executed by either surefire or failsafe plugin), the outcome of the tests executed will be picked up automatically by Jenkins, just like it picks up other/regular jUnit tests (as surefire or failsafe will include them in their XML reports and Jenkins will pick these up).
You can find a sample Maven FitNesse project using (a slightly customised version of) this approach at https://github.com/fhoeben/sample-fitnesse-project. How to run the tests on Jenkins is described at https://github.com/fhoeben/hsac-fitnesse-fixtures#to-run-the-tests-on-a-build-server:
Have the build server checkout the project and execute mvn clean test-compile failsafe:integration-test. The result in JUnit XML results can be found in: target/failsafe-reports (Jenkins will pick these up automatically for a Maven job)
You indicate you don't need the HTML results, but they will be made available. They can be found in: target/fitnesse-results/index.html, and you could choose to use the 'HTML Publisher' Jenkins plugin to link to them from each build.

Class name in Junit Request Sampler disappearing in Jmeter 2.13

When i select any class and testmethod as Junit 4 test case, it disapears as soon as i click something else and a default test case comes up that gives me a null exception,for eg: groovy test case/Selenese Test Case. I require the Groovy Library for my test case.
This happens only in Jmeter 2.13, but this unchecking thing does not happen in Jmeter 2.11, but i need to use the Backend Listener that is only in Jmeter 2.13.
Image that shows the selection of the junit testcase
Image that shows that the test selected is rechecked by some default groovy test case/Selenese Test case
Screenshot of jmeter using Nightly Build
I need a solution to this, please help me out. Thank you
It appears you are facing a NPE in a process related to undo/redo feature:
https://github.com/apache/jmeter/blob/v2_13/src/core/org/apache/jmeter/gui/GuiPackage.java#L853
Could you try to remove jmeter-plugins 1.4.0 which is a developer snapshot.
Try without it, and if it works report a bug to jmeter-plugins.org
Then try with jmeter-plugins-1.3.1 which is the stable version, it might work but the bug might also be in it.
I created bug:
- https://bz.apache.org/bugzilla/show_bug.cgi?id=58795
It is now fixed in nightly build so you will have more informations to provide to jmeter-plugins or jmeter.
To use nightly build:
http://jmeter.apache.org/nightly.html
Download the _bin and _lib files
Unpack the archives into the same directory structure
The other archives are not needed to run JMeter.

generating reports in Jenkins

Need to run a job in Jenkins after successfully running the tests it needs to perform as post-build action for generating test reports
For this i have configured
Publish JUnit test result report
In the field
Test Report XMLs: continuum/*/target/surefire-reports/*TestSuite.xml
'continuum/*/target/surefire-reports/TestSuite.xml' doesn't match anything: 'continuum' exists but not 'continuum//target/surefire-reports/*TestSuite.xml'
Can you please help me out in resolving the error....??
I assume you have an 'Execute JUnit tests' Build step. This will produce a JUnit XML file to a location you specify, say, TestOutput/junitresults.xml.
In the 'Publish JUnit test result report' Post Build step you just need to specify TestOutput/junitresults.xml.
As long as your tests executed and produced the output file the Post Build step won't fail to publish it, whether the tests failed or not.
You shouldn't be trying to publish files in the surefire-reports directory unless that it where you told JUnit to write its output file. Normally you wouldn't.
If you want to make it even simpler just tell JUnit to write its output file to the Jenkins WORKSPACE root by removing the TestOutput/ and just specify junitresults.xml.

How to use tempus-fugit in eclipse to run junits in parallel without modifying the source code?

Based on the information in following link I am able to run junits in parallel from eclipse by adding #RunWith(ConcurrentTestRunner.class) to my test classes .
https://stackoverflow.com/a/13063715/825707
But I have a legacy code with around 400 junit test classes and around 4000 test cases. I don't want to update the 400 java files with #RunWith(ConcurrentTestRunner.class) , is there a way to create a suite or a change in plugin so that I am able to run all of them in parallel without modifying my source code ?
Thanks
Shakti

Generating JUnit reports from the command line

I have a test setup for a cloud system that uses a mixture of python for process level control and junit for internal state inspection. Essentially, I bring up several VMs to server as the cloud and then a junit VM which is a member of the cloud but drives tests and checks internal state. Our existing cloud management stuff is driven by python and I would like to maintain this.
I have a working setup that will run the JUnit command line via
java -ea -cp <classpath> org.junit.runner.JUnitCore <tests>
but this does not produce an report file. I know that ant is capable of producing an xml report, but I do not want to involve ant in this process (I have enough moving parts already).
Is there a way to launch junit from the command line such that it produces a report?
Ideally, I would have the junit tests produce xml reports, the python tests produce xml reports, and then merge them together for consumption by our CI system.
Update: The command line execution must support Windows, Linux, and Mac. We are not allowed to ship an external ant, although packaging an internal ant might be an option.
The JUnit library does not have any XML output options. To achieve such a thing, you'll need to write your own RunListener, which listens for the output and will in your case write the XML file.
However, to get the XML file in the correct format so that it can be read by CI system, I think it would be far easier to just use ant, either via the command line using a build.xml (JUnitReport), or using the java api: How can i use Apache ANT Programmatically.
EDIT: Initially, we had four options:
Use ant from the command line
Use ant programmatically (using the Java API)
Use the XMLJUnitResultFormatter directly with JUnitCore
Create a custom RunListener which produces the correct XML output.
Given the restrictions added by the OP, we can't use ant from the command line, which eliminates 1.
After looking more closely at the Ant JUnit task, it seems to be impossible to use this with JUnitCore (adding a TestListener), because ant uses the name of the test class directly, so you can't do a bridge class. From XMLJUnitResultFormatter.java
private void formatError(String type, Test test, Throwable t) {
...
nested.setAttribute(ATTR_TYPE, t.getClass().getName());
String strace = JUnitTestRunner.getFilteredTrace(t);
Text trace = doc.createTextNode(strace);
nested.appendChild(trace);
}
This eliminates 3.
Invoke Ant programmatically, via the Java API. I can't find any recent documentation on this. This seems to be hard.
So, finally, I would do 4, a custom RunListener, using the code from XMLJUnitResultFormatter as a base. And then, I'd publish it on github.com, so this question could be answered properly :-)