Fail ant build by checking junit report? - java

I need to cause my build to fail based only on the junit report. Is there a way to do this. I know how to fail the build using haltonfailure in junit tag, but in my build.xml I have access only to the junit report. I am using ant.

Try something like
<fail if="testFail" message="At least one unit test failed"/>
in your unit test target.

Refer to this: http://ant.apache.org/manual/Tasks/junit.html ,
try using failureproperty="failed.unit.test.property" inside junit ant task & check if its set & fail when your run completes with :
<fail if="failed.unit.test.property" message="Unit tests failed with more custom msg to your test class/suite"/>

Related

Generate Trace of JUnit test on success

I have JUnit tests that work without errors. And what I would like to do is to generate a trace file of these tests for example havinge execution time of each test class, list of methods tested ant other.
Thank you.
Your build tool should do this for you. For instance if you are using maven have a look at http://maven.apache.org/surefire/maven-surefire-report-plugin/, for ant you could use https://ant.apache.org/manual/Tasks/junit.html and https://ant.apache.org/manual/Tasks/junitreport.html.

Run single TestNG test with maven by using testng.xml

I have defined my tests in a parametrized testng.xml. I use the Failsafe plugin and run my tests with mvn verify. The whole suite is executed.
What if I have to run only one single test from my testng.xml suite? I want that the parameters will be used, but I want to run only one test from the command line.
The maven parameter:
-Dit.test=CheckoutIT#testOrderId
does not work because maven runs the test directly without testng.xml, the parameters are not bind and the test will be ignored.
Is there a way to do it? A workaround is to create a temporary suite xml with only one test but it can't be a solution...
Best regards Robert
According to testng doc:
The command line flags that specify what tests should be run will be ignored if you also specify a testng.xml file, with the exception of -includedgroups and -excludedgroups, which will override all the group inclusions/exclusions found in testng.xml.
Another solution is to add listener to your maven goal which will parse your testng.xml and get test parameters to apply them to your current test.

Running TestCases (from Maven) when TestCases are in src?

I have a project that itself is a set of test cases for an application. The test cases are tested itself using a mockup of the application to ensure the tests itself is correct. This is important to ensure the test cases justify some sort of specifications that are hard to follow and easy to mess up.
Now I want the final tests (those who are tested before) being in src in Maven. As expected mvn test just executes the test cases of the test cases not the test cases themself.
So basically how do I execute test cases that reside inside the 'src' folder using a maven goal?
Try this :
<testSourceDirectory>src</testSourceDirectory>

Jenkins - Selecting tests

I am currently working on a Maven Project, using JUnit for defining tests and Jenkins for CI and am looking into how I can group my tests.
Say I had a test class with 20 tests, but I don't want to run all 20 tests, I want to be able to configure which tests to run. For Example, in another standalone project using TestNG and Selenium you can create a test method with the following annotation:
#Test (groups = { "AllTest" })
public void myTestMethod()
{
.. do something
.. assert something
}
... and then I am able to call which group to run based on an XML configuration.
Is it possible to define such type of groupings using Jenkins? I have researched into this and came across the plugin "Tests Selector Plugin" however can't understand how to get started once I've installed the plugin. There is a Wiki Page for it but I can't understand what to do after installing.
I have copy pasted the example property file, and didn't really understand what I needed to manipulate in it. When building, I simply get that the property file cannot be found or Jenkins doesn't have permission; can't find a way around this either :(
It's possible via maven + maven-surefire-plugin
http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html
You can run a single test, set of tests or tests by regexp.

No unit test success value reported to sonar

I am using Jenkins with Sonar to perform a build of my Java EE application through an ANT script.
The build works fine and the unit test case run fine as well.
I am currently getting a unit test coverage % but the "Unit test sucess" shows as zero. When I click on the "0 tests" which is available to me as a link on the Sonar dashboard, I get to see the different modules of my Java EE application which Sonar ran through as defined in the build.xml used by Jenkins.
After some research online and reading through a similar Stackoverflow question at this link - Unit test success reported as zero by Sonar
I added the following property tags in my build.xml (used by Jenkins) located in my Java EE application root folder and in the sonar.xml files residing in every sub folder which is defined as a module in the build.xml file:
<property name="sonar.java.coveragePlugin" value="jacoco" />
<property name="sonar.junit.reportsPath" value="ABCD/testreport/" />
<property name="sonar.jacoco.reportPath" value="ABCD/build/classes/jacoco.exec" />
where "ABCD" is the directory which I use to house my Junit test case JAVA files.
The ANT script xml file does contain a junit task which compiles executes my unit test cases in the Jenkins build before giving the hanndle to Sonar. Since I know I am getting a unit test coverage, I know these unit tests are being seen to a degree but what additional steps do I need to take to make the unit test success show up with a value greater than zero?
Please advise.
Thanks in advance.
Subbu

Categories