Having a very basic issue with running tests in a Java Play 2.0 app. It won't pick up my tests.
I've tried to put a test folder in the root of the project and use Junit as the docs seem to suggest. This results in:
$ play test
[info] Loading project definition from /Users/.../play20TestTest/project
[info] Set current project to play20TestTest (in build file:/Users/.../testapps/play20TestTest/)
[info] No tests to run for test:test
[success] Total time: 1 s, completed May 22, 2012 11:16:52 AM
I've also tried putting test under app. This at least picks up my code, but the test packages aren't available on my classpath so I assume it's incorrect.
I made a simple example and copied SimpleTest from the docs exactly: https://github.com/jsimone/Play2UnitTest
You placed your test in test/test/SimpleTest.java, move it to test/SimpleTest.java and it will work with play test command.
Related
I have a maven project (multimodule, JDK 11) that has a lot of modules and tests within it.
I suddenly noticed that one of my tests is NOT invoked as part of the surefire plugin.
Other tests in the same module do get to be invoked successfully.
I am able to run this test successfully via Intellij. The test is not disabled nor ignored. it contains a set of #Test methods. In addition, I am able to run it specifically using mvn test -Dtest=... argument.
The test class gets to be compiled successfully and appears in target/test-classes.
(I have already run with -X and could not find relevant additional data there)
I am working with surefire plugin 2.22.1 ; junit-vintage-engine:5.2.0 ; junit-platform-runner:1.2.0 ; Spring Boot 2.5.3 (with BOM) ; My test is spring based and invoked using #ExtendWith(SpringExtension.class)
(I do have other spring based tests that are invoked as expected though).
Following this question, I have also tried to work with 2.22.2. It did not solve the problem
Following this question, I have verified and indeed all tests in the test class that does not invoke are prefixed with the 'test' word
EDIT:
The problem happens in a test that belongs to a module that is part of a larger project in my company, which inherits various defaults across the POM inheritance chain. Unfortunately, I can not isolate only my POM out of it and present it.
I have tried to reproduce the problem in a new isolated project but did not succeed (that is, all the tests were invoked as expected).
What am I missing? Is there a hidden switch of the surefire plugin that reveals what's going on under the hood and where do surefire pull the list of tests he is meant to execute?
The surefire plugin (by default) will run only tests with the following name syntax ...
"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
More details can be found here
Problem solved!
Following #Kathrin Geilmann comment:
...By default surefire only executes: ...Test.java, Test....java,
...Tests.java and ...TestCase.java
The name of my file ended with ...Tester (!##$$%^)
Thanks.
There are a bunch of questions related to the issue that mvn test doesn't execute test classes where the answer is always, that maven-surefire looks for certain prefixes or postfixes of filenames. I already considered this and it didn't help me as my filenames where already valid.
When I execute mvn test, the log contains the following section:
[INFO] --- maven-compiler-plugin:3.8.1:testCompile
(default-testCompile) # compiler --- [INFO] Changes detected -
recompiling the module! [INFO] Compiling 5 source files to
/project_path/target/test-classes
... so mvn test does actually find my test cases, and indeed, I can find all the compiled test classes in the directory /project_path/target/test-classes/
But still, only one of these 5 test files is actually executed and its tests are run whereas the other 4 are ignored by mvn test.
Any ideas why that could be the case? I am not really sure which additional information could be helpful to answer this question. Just ping me if there is something that I need to add to the question.
I just found a way to fix it..
Honestly, I don't understand why this makes the difference, but I have used #Test annotations on my test cases from org.junit.jupiter.api.Test in the file that was executed correctly by mvn test and used #Test annotations from org.junit.Test in the other files (which were not executed).
I've changed all files to import the #Test annotation from the jupiter package and then all tests were recognized.
When trying to run mvn test on Windows, my tests run fine, but on CentOS 7 I get this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.403s
[INFO] Finished at: Mon Jan 27 10:54:06 CET 2020
[INFO] Final Memory: 17M/119M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GenericTests: Compilation failure
[ERROR] /home/gitlab-runner/builds/5KQvSgfo/0/webdriver_projects/webdriver_bv/test_dir/src/test/java/genericTests/Contact/InputMaxLengthTest.java:[18,7] error: error while writing InputMaxLengthTest: could not create parent directories
This happens with a few other tests too, although not all of them. I don't understand why. These tests don't interact with folders and in fact aren't particularly different from any other test.
The only file system interaction I have is that I take screenshots and place them in a folder, using org.apache.commons.io.FileUtils, but I have permissions on that folder. And it happens even when I comment out the file writing instructions so I don't know if it's that.
On top of adding a screenshot feature, I've since changed my pom.xml to have
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
and I have to point to the JDK 13 location via export JAVA_HOME=/usr/java/jdk-13.0.2 before running mvn. It must be either of those things. What could be the cause? Consider that this works just fine on Windows.
I've tried:
deleting the screenshot instruction (didn't work)
changing the compiler source/target to 8, as it was before (didn't work)
I didn't want to try to delete the culprit tests one by one to see if all tests had this problem or not as that would be time consuming.
EDIT: I also ran dos2unix in every file of the project, but the result is the same.
Here's the line where I take a screenshot and write to a file, done in every single test:
#After
public void tearDown() throws Exception {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
if (OSChecker.isWindows()) {
FileUtils.copyFile(scrFile, new File("screenshots\\" + formatScreenshotFilename()));
}
else {
FileUtils.copyFile(scrFile, new File("screenshots/" + formatScreenshotFilename()));
}
}
You should upgrade your configuration to use most recent version 3.8.1 of maven-compiler-plugin cause you are using a very old version.
My appium android test compiles successfully on local. I prepared and uploaded the same test on app center's test cloud following the prep guidelines: https://learn.microsoft.com/en-us/appcenter/test-cloud/preparing-for-upload/appium.
I Packed the test class and all dependencies into the target/upload folder and performed the upload. The project was scanned and the runner class was correctly identified. Console says Build Success but the test did not run. The output says Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
A final error was displayed: Cannot run tests. Returning exit code 2
From the logs, what could I have done wrong? I did a google research and found that exit code 2 means Invalid Options but what on earth does that mean?
This most likely is a naming issue.
According to the Maven Surefire conventions for inclusion of tests you must name the tests:
"/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
It seems that this is a quite common issue and I personally stumbled on it at least a couple of times.
Some of the main causes being:
Forgetting to run the test (and thus create the test classes) before running pitest: Pitest can't detect class of test, PITest cannot find tests.
Miss-configured targetTests: pitest doesn't find tests
Improper use of the assert keyword: pitest not able to locate junit test
However, today I stumbled upon a new case of 0 tests found, which I struggle to solve. Let us consider this project: https://github.com/bonnyfone/vectalign.
It is a small project and includes one only test class:
src
|
+- main
| |
| ...
|
+- test
|
+- java
|
+- VectAlignTest.java
I added pitest to the pom.xml:
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.3.2</version>
</plugin>
I run the command mvn clean test org.pitest:pitest-maven:mutationCoverage.
While the test run just fine, for some reason pitest cannot locate them:
12:23:16 PM PIT >> INFO : MINION : 12:23:16 PM PIT >> INFO : Found 0 tests
...
================================================================================
- Statistics
================================================================================
>> Generated 910 mutations Killed 0 (0%)
>> Ran 0 tests (0 tests per mutation)
You can find the complete pom.xml here: https://pastebin.com/F28ZpcMk
And here is the complete output for mvn clean test org.pitest:pitest-maven:mutationCoverage: https://pastebin.com/tWHgq43a
Now my question is, what is going wrong in this particular case? How does pitest determine which are the test classes?
Your help would be much appreciated :)
PITest did not find my classes or test classes because I did not have them in a package. Once I put them in a package, everything worked great. I suspect that you could also specify the class and test class locations manually.
To quote that answer at the (now deleted) linked question:
I just spent a great deal of time with the same message
No mutations found. This probably means there is an issue with either the supplied classpath or filters.
My problem was simple: I had created a couple of test projects in
IntelliJ using Maven. But I did not have a package. I was using the
default package and PITest was failing every time. The PITest has a
plugin that might work with just the default package if you specify
the class and test classes. But all the documentation said that it
should work by default. A verbose output even showed that PITest was
finding the correct project folders, but it still didn't work. Henry
Cole was even good enough (the developer of PITest) to look at my
POM.xml file and confirm that it looked good.
In summary, PITest works great if you put your Java code in a package.
I am facing quite the same issue. For me specifying the exact test packages helped. In your case maybe you could add:
<configuration>
<targetTests>
<param>VectAlignTest*</param>
</targetTests>
</configuration>
But of course, this is quite a dirty workaround. Maybe somebody knows the root cause of the problem.