junit4 output interpretation - junit

My console output from running JUnit in cmd.exe looks like:
JUnit version 4.10
.....I
Time: 0,469
OK (5 tests)
What does the I on the second line mean?

It means that the test has been #Ignored.

Related

How to run selenium IDE on chrome

I want to run selenium IDE on chrome. for that i have to write following cmd command. As it is shown here
E:\Automation\Selenium>java -jar selenium-server-standalone-3.5.3.jar chromedriver.exe
But it gives me the error like below :
Exception in thread “main” com.beust.jcommander.ParameterException: Was passed main parameter ‘chromedriver.exe’ but no main parameter was defined
at com.beust.jcommander.JCommander.getMainParameter(JCommander.java:914)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:759)
at com.beust.jcommander.JCommander.parse(JCommander.java:282)
at com.beust.jcommander.JCommander.parse(JCommander.java:265)
at com.beust.jcommander.JCommander.(JCommander.java:210)
at org.openqa.grid.selenium.GridLauncherV3$1.setConfiguration(GridLauncherV3.java:227)
at org.openqa.grid.selenium.GridLauncherV3.buildLauncher(GridLauncherV3.java:155)
at org.openqa.grid.selenium.GridLauncherV3.main(GridLauncherV3.java:75)
Please let me know if am doing anything wrong in the above command.
You need to run it like this
java -jar -Dwebdriver.chrome.driver=chromedriver.exe selenium-server-standalone-3.5.3.jar

mvn package failed because no runnable methods but run junit test in eclipse is ok

Spring boot project, there is a web integration test, when execute it in eclipse (run as > junit test) it's ok.
public class ReservationControllerIntegrationTest extends BaseWebIntegrationTest{...}
but when run mvn clean package , encountered below error:
initializationError(com.foo.web.BaseWebIntegrationTest) Time elapsed: 0.005 sec <<< ERROR!
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:140)
when I changed
public class BaseWebIntegrationTest
to
public abstract class BaseWebIntegrationTest
then run mvn clean package again, this time it is build successfully!
So why run junit test in eclipse do not need to specify abstract explicitly?
The mvn surefire plugin auto-detects test suites based on some simple rules applied to all the classes it finds under src/main/test. In particular, it looks for all concrete classes matching a particular naming convention.
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
In your case the plugin thinks that BaseWebIntegrationTest is a test suite, because it matches the naming convention, but it's not finding any test methods in it. When you made the class abstract the plugin skipped it because it was no longer instantiable. You could also have renamed the class so that it didn't end in the word Test.
When you run the test in Eclipse I'm guessing you run the specific integration test (ReservationControllerIntegrationTest) and so Eclipse doesn't try to treat BaseWebIntegrationTest as a test suite.

JUnit are failing when upgraded from JDK 1.6 to JDK 1.8 in maven, but its works in eclipse

I am using the JUnit for code coverage in my project. For db i am using the dbunit as like mock DB. When i am running JUnit from Eclipse UI its getting passed, but its getting failed when run through maven.
Above set up is running fine in JDK 1.6.25 by using maven and its started failing when upgraded to 1.8.51. I had updated the maven compiler plugin, its doesn't work. I am used below versions, junit - 4.7 2.dbunit - 2.4.8 hsqldb - 2.0.0 maven - 2.2.1.
Issue:
-> All test cases which ran fine in JAVA 1.6, started failing on migrating to JDK 1.8.51.
-> Due this we faced build failure issue and also code coverage reduction.
Root Cause:
-> JUnit uses Java reflection to get the test methods from Test classes. In JAVA 1.6 test method order returned as same as declaration in source file.
-> But from JAVA 7 onwards the methods order returned the by JVM is not same as the source file, it will be returned randomly.
-> Since our test cases are dependent on each other, due to order change it started failing.
For Example below test cases are using the same data (Mock DB) for execution,
-> AddOperationTestCase()
-> EditOperationTestCase()
-> DeleteOperationTestCase()
If delete run first due JVM random order, for Add and Edit data won't be available it will fail.
Solution :
-> I had tried to find options in JUnit and Sure Fire plugin to maintain same order as like source file, but I could not find feasibility there.
-> I have identified the class which will returns the order of execution in JUnit library and override that accordingly to run it source file order.
-> As of now I had added this annotation wrapper to failed classes, now build is running successfully.
Link for Wrapper class:
https://somethingididnotknow.wordpress.com/2014/03/07/run-junit-tests-in-order/

Why is PHPUnit creating the output "S" for a test that passes?

I'm using PHPUnit in Eclipse IDE and this is the output when running my unit test:
PHPUnit 3.7.28 by Sebastian Bergmann.
.S.........
Time: 190 ms, Memory: 5.50Mb
OK (10 tests, 45 assertions)
The output has an S which suggests that a test is being skipped. However, there is no message "Skipped: 1".
According to the manual, the test output should look like this:
.S.........
Time: 190 ms, Memory: 5.50Mb
1) UnitTest_Directory_Test::testBenthicCover
The MySQLi extension is not available.
/home/sb/DatabaseTest.php:9
OK, but incomplete or skipped tests!
OK (10 tests, 45 assertions, Skipped: 1)
Is the test actually passing, or is it being skipped?
Why do I not see Skipped: 1?
Environment: PHPUnit 3.7.28, Eclipse Java EE IDE, Version: Helios Service Release 2
I've logged the test results in json format for debugging:
{"event":"suiteStart","suite":"UnitTest_Directory_Test","tests":10}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testBenthicCover"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testBenthicCover","status":"pass","time":0.27545499801636,"trace":[],"message":"","output":"S"}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfMeasurementAverage"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfMeasurementAverage","status":"pass","time":0.17307710647583,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testEqualNumberOfSamplingUnitsPerSurveyParentToChild"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testEqualNumberOfSamplingUnitsPerSurveyParentToChild","status":"pass","time":0.0017728805541992,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfCountPerUnitArea"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfCountPerUnitArea","status":"pass","time":0.0038161277770996,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfFishCountPerUnitArea"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfFishCountPerUnitArea","status":"pass","time":0.0051858425140381,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfPercentCover"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfPercentCover","status":"pass","time":0.0044069290161133,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfGramsPerUnitArea"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfGramsPerUnitArea","status":"pass","time":0.0045709609985352,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfGramsPerUnitVolume"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfGramsPerUnitVolume","status":"pass","time":0.0045430660247803,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfTonsPerUnitAcreFromGramsPerUnitArea"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testCalculationOfTonsPerUnitAcreFromGramsPerUnitArea","status":"pass","time":0.0042028427124023,"trace":[],"message":"","output":""}
{"event":"testStart","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testParentEqualities"}
{"event":"test","suite":"UnitTest_Directory_Test","test":"UnitTest_Directory_Test::testParentEqualities","status":"pass","time":0.0016450881958008,"trace":[],"message":"","output":""}

Error while running JUnit test from command line

I am trying to run a single JUnit test from the command line but I am getting an error.
I could compile the JUnit test successfully and the class file gets created in the correct location.
But when I try to run it using:
C:\Program Files\Java\jdk1.7.0_01\bin>java org.junit.runner.JUnitCore C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class
I get the error:
JUnit version 4.8.1
Could not find class: C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDesc
ribbing
I don’t know why it is not able to find the class even though it exists in the said location.
You need to specify the name of the class on the command line, not the filename:
java org.junit.runner.JUnitCore com.org.tests.Nav
From the javadoc for JUnitCore:
JUnitCore is a facade for running tests. It supports running JUnit 4
tests, JUnit 3.8.x tests, and mixtures. To run tests from the command
line, run java org.junit.runner.JUnitCore TestClass1 TestClass2 ....
For one-shot test runs, use the static method runClasses(Class[]). If
you want to add special listeners, create an instance of
org.junit.runner.JUnitCore first and use it to run the tests.
and you will have to add the bin directory (note NOT the src) to the classpath of the command line as well. This may look like:
java -cp C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\bin org.junit.runner.JUnitCore com.org.tests.Nav