JUnit test report testsuite's timestamp is epoch - junit

In my test execution, some junit classes report that their timestamp is 1970. Why might this happen?
<testsuite name="my.BlahTest" tests="2" failures="0" errors="0"
timestamp="1970-01-01T00:00:00" hostname="DEV-DT22" time="1.36139893834E9">
This does not happen to the same classes each test run. Nor does it ever happen to all of the classes. I'm using the java plugin for gradle to execute the JUnit tests and have never noticed this issue when using JUnit via Ant.

Might be a bug. Please report it at http://forums.gradle.org and include as many details as you can (test task configuration, ways to reproduce, Gradle version, etc.).

Related

How to re-run only the failed test cases with Junit test suite

I'm new to Junit. I've created a test suite with 50 test cases. If I run it passes only 30 test cases and 20 test cases are failing. How I can achieve running only those 20 failed test cases again with the help of Junit? Is it possible? Can someone guide on this?
Deciding which tests to run, and in which order, is the job of the test runner. So, to rerun only failed tests you need to use a test runner that records which tests passed or failed, and which can be instructed to run only tests it knows failed.
The tested runner in the Eclipse IDE can do this. Typically, and IDE is the only place you need this functionality, because an IDE is interactive and when using it you want fast feedback on whether a fix works. This functionality is not so useful elsewhere because in other contexts we typically want to check that the program passes all its tests.

TestNG, Junit and log4j

Is there any easy way to configure log4j so that in unit tests I only print the stacktrace of the failing tests without having noise in the output on the shell?
Right now when I execute tests I can see the output printed by the classes I am testing. I want to avoid that since it's not bringing any value for passing tests
I would recommend to have log4j.properties file under src/test/resources with content:
log4j.rootLogger=OFF
As result all your production classes will not log but the jUnit or testNG will print the failed tests as you expect.
In your unit test, set the log level to the level at which stacktraces are being logged:
Logger.getRootLogger().setLevel(Level.WARNING);

JMockit and parameterized tests (JUnit parameterized or JUnitParams)

I was wondering if JMockit is compatible with JUnit parameterized tests or JUnitParams, because I haven't found a way to make them work together so far, since you can only specify one JUnit runner, and both JMockit, JUnitParams and Parameterized require you to use their own runner.
JMockit does not require you to use an own runner. Using an own runner is just one of the possible ways to make sure JMockit got initialized properly before your tests run. You can also add JMockit as Java agent via commandline parameters, depend on classpath ordering (having JMockit in the classpath before JUnit) or call the JMockit initialization method manually before the actual tests start if you have such a place where you can call it, e. g. if you use an own JUnit runner.

"smart" JUnit test ordering

I want to add some hints to my build, to run certain tests "first" without re-running them later.
Simply add Class names to a "priority" string in an input parameter to my test task, or
Have JUnit's testers smart enough to remember/persist failing test class names, so that the next time around the builder runs those first.
What is the most idiomatic way of doing this in Ant?
The following tools might help you to achieve the desired JUnit test execution order, but they depend on Eclipse usage:
Continuous Testing for Eclipse (CT-Eclipse)
JUnit Max
infinitest
I have not used any of those tools, and I have no Ant-only solution.
You might consider these related posts:
Run JUnit automatically when building Eclipse project
Starting unit tests automatically after saving a file

fail hudson build on single unit test failure

Is there a way to cause hudson to report a build as failed, rather than unstable, if only a single unit test fails? thanks.
Hudson actually enables the ignoring of test failures. It just needs to be put as a property in hudson.
-Dmaven.test.failure.ignore=false
It's actually not a good idea to fail the build if tests failed when using hudson. Problem is hudson will not report the state of test pass/fail if the build fails. If the build fails, hudson deems it to not have completed properly and thus does not act on the result.
There are two properties to the junit task
errorProperty="maven.test.error"
failureProperty="maven.test.failure"
After the junit tag you should be able to do something like this
<fail message="Test failed!!!" if="maven.test.error" />
<fail message="Test failed!!!" if="maven.test.failure" />
But don't nail me on this
If you're using Ant to drive the build, you can configure the JUnit task to halt on failure. Is that what you mean?
Look through your job configuration, I believe there is a property (check box) that says fail on test failure, or something of the sort. We use this on some of our projects at my work.
Otherwise if you want to use the Ant method as suggested maven can run ant tasks...