When I run this test from VSCode or Intellij it works fine. When I run it from Maven using the command below it fails.
Getting this error: .apache.maven.plugin.MojoFailureException: No tests were executed!
When running this command:
mvn -Dtest=Lab5bTests#testAllSubclassesSetPackaging test
on this test:
@Test
public void testAllSubClassesSetPackaging() {
// test candy
// test cookie
// test iceCream
// test sundae
assertDoesNotThrow(() -> {
Method getCandyPackagingMethod = candyClass.getMethod("getPackaging");
String actualPackaging = (String)getCandyPackagingMethod.invoke(candyObject);
assertTrue("Bag" == actualPackaging, "Candy should have packaging set to Bag.");
Method getCookiePackagingMethod = cookieClass.getMethod("getPackaging");
actualPackaging = (String)getCookiePackagingMethod.invoke(cookieObject);
assertTrue("Box" == actualPackaging, "Cookie should have packaging set to Box.");
Method getIceCreamPackagingMethod = iceCreamClass.getMethod("getPackaging");
actualPackaging = (String)getIceCreamPackagingMethod.invoke(iceCreamObject);
assertTrue("Bowl" == actualPackaging, "IceCream should have packaging set to Bowl.");
Method getSundaePackagingMethod = sundaeClass.getMethod("getPackaging");
actualPackaging = (String)getSundaePackagingMethod.invoke(sundaeObject);
assertTrue("Boat" == actualPackaging, "Sundae should have packaging set to Boat.");
});
}
but the next test in the test class does not throw the error, and is almost exactly the same test.
mvn -Dtest=Lab5bTests#testAllSubClassesHaveUpdatedToString test
@Test
public void testAllSubClassesHaveUpdatedToString() {
// test candy
// test cookie
// test iceCream
// test sundae
assertDoesNotThrow(() -> {
Method candyToStringMethod = candyClass.getMethod("toString");
String actualString = (String)candyToStringMethod.invoke(candyObject);
assertTrue(actualString.contains("Bag"), "Candy toString should contain bag.");
Method cookieToStringMethod = cookieClass.getMethod("toString");
actualString = (String)cookieToStringMethod.invoke(cookieObject);
assertTrue(actualString.contains("Box"), "Cookie toString should contain box.");
Method iceCreamToStringMethod = iceCreamClass.getMethod("toString");
actualString = (String)iceCreamToStringMethod.invoke(iceCreamObject);
assertTrue(actualString.contains("Bowl"), "IceCream toString should contain bowl.");
Method sundaeToStringMethod = sundaeClass.getMethod("toString");
actualString = (String)sundaeToStringMethod.invoke(sundaeObject);
assertTrue(actualString.contains("Boat"), "Sundae toString should contain boat.");
});
}
Why does it fail in Maven when it passes in VSCode? Why does it fail when the second test passes in Maven?
Any idea as to what I am missing here???
Throwing the -e to add extra info did not reveal much but here is the stack trace:
[ERROR] Failed to execute goal .apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project CS115-Lab1a-JavaBasicsReview: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal .apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project CS115-Lab1a-JavaBasicsReview: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at .apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at .apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at .apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at .apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at .apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at .apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at .apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at .apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at .apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at .codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
at .codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
at .codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
at .codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: .apache.maven.plugin.MojoFailureException: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
at .apache.maven.plugin.surefire.SurefireHelper.reportExecution (SurefireHelper.java:147)
at .apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:373)
at .apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:1018)
at .apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:848)
at .apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at .apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at .apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at .apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at .apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at .apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at .apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at .apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at .apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at .apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at .codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
at .codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
at .codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
at .codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"
xmlns:xsi=";
xsi:schemaLocation=".0.0 .0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>.example</groupId>
<artifactId>CS115-Lab1a-JavaBasicsReview</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<mavenpiler.source>17</mavenpiler.source>
<mavenpiler.target>17</mavenpiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Need at least 2.22.0 to support JUnit 5 -->
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run this test from VSCode or Intellij it works fine. When I run it from Maven using the command below it fails.
Getting this error: .apache.maven.plugin.MojoFailureException: No tests were executed!
When running this command:
mvn -Dtest=Lab5bTests#testAllSubclassesSetPackaging test
on this test:
@Test
public void testAllSubClassesSetPackaging() {
// test candy
// test cookie
// test iceCream
// test sundae
assertDoesNotThrow(() -> {
Method getCandyPackagingMethod = candyClass.getMethod("getPackaging");
String actualPackaging = (String)getCandyPackagingMethod.invoke(candyObject);
assertTrue("Bag" == actualPackaging, "Candy should have packaging set to Bag.");
Method getCookiePackagingMethod = cookieClass.getMethod("getPackaging");
actualPackaging = (String)getCookiePackagingMethod.invoke(cookieObject);
assertTrue("Box" == actualPackaging, "Cookie should have packaging set to Box.");
Method getIceCreamPackagingMethod = iceCreamClass.getMethod("getPackaging");
actualPackaging = (String)getIceCreamPackagingMethod.invoke(iceCreamObject);
assertTrue("Bowl" == actualPackaging, "IceCream should have packaging set to Bowl.");
Method getSundaePackagingMethod = sundaeClass.getMethod("getPackaging");
actualPackaging = (String)getSundaePackagingMethod.invoke(sundaeObject);
assertTrue("Boat" == actualPackaging, "Sundae should have packaging set to Boat.");
});
}
but the next test in the test class does not throw the error, and is almost exactly the same test.
mvn -Dtest=Lab5bTests#testAllSubClassesHaveUpdatedToString test
@Test
public void testAllSubClassesHaveUpdatedToString() {
// test candy
// test cookie
// test iceCream
// test sundae
assertDoesNotThrow(() -> {
Method candyToStringMethod = candyClass.getMethod("toString");
String actualString = (String)candyToStringMethod.invoke(candyObject);
assertTrue(actualString.contains("Bag"), "Candy toString should contain bag.");
Method cookieToStringMethod = cookieClass.getMethod("toString");
actualString = (String)cookieToStringMethod.invoke(cookieObject);
assertTrue(actualString.contains("Box"), "Cookie toString should contain box.");
Method iceCreamToStringMethod = iceCreamClass.getMethod("toString");
actualString = (String)iceCreamToStringMethod.invoke(iceCreamObject);
assertTrue(actualString.contains("Bowl"), "IceCream toString should contain bowl.");
Method sundaeToStringMethod = sundaeClass.getMethod("toString");
actualString = (String)sundaeToStringMethod.invoke(sundaeObject);
assertTrue(actualString.contains("Boat"), "Sundae toString should contain boat.");
});
}
Why does it fail in Maven when it passes in VSCode? Why does it fail when the second test passes in Maven?
Any idea as to what I am missing here???
Throwing the -e to add extra info did not reveal much but here is the stack trace:
[ERROR] Failed to execute goal .apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project CS115-Lab1a-JavaBasicsReview: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal .apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project CS115-Lab1a-JavaBasicsReview: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at .apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at .apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at .apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at .apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at .apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at .apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at .apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at .apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at .apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at .codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
at .codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
at .codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
at .codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
Caused by: .apache.maven.plugin.MojoFailureException: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)
at .apache.maven.plugin.surefire.SurefireHelper.reportExecution (SurefireHelper.java:147)
at .apache.maven.plugin.surefire.SurefirePlugin.handleSummary (SurefirePlugin.java:373)
at .apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked (AbstractSurefireMojo.java:1018)
at .apache.maven.plugin.surefire.AbstractSurefireMojo.execute (AbstractSurefireMojo.java:848)
at .apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
at .apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
at .apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
at .apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
at .apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at .apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at .apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at .apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at .apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at .apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at .apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at .apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at .apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at .apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at .codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
at .codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
at .codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
at .codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache./POM/4.0.0"
xmlns:xsi="http://www.w3./2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache./POM/4.0.0 http://maven.apache./xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>.example</groupId>
<artifactId>CS115-Lab1a-JavaBasicsReview</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<mavenpiler.source>17</mavenpiler.source>
<mavenpiler.target>17</mavenpiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Need at least 2.22.0 to support JUnit 5 -->
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<groupId>.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Share
Improve this question
edited Mar 18 at 2:10
Daltin
asked Mar 17 at 19:24
DaltinDaltin
1119 bronze badges
5
- Why are you using an ancient old version: ` .apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test` ... use most recent version of the plugin.. maven.apache./plugins and it would helpful to see the pom file.. – khmarbaise Commented Mar 17 at 20:39
- I added the POM file. Not sure on versions. Using what I was told to use. Runs in GitHub Classroom using autograding, but I test it on my local. Not sure if there are version constraints in the GitHub Classroom environment. – Daltin Commented Mar 18 at 2:11
- Are the tests both in the same class? if not, are the import statement the Test annotations for them the same? – John Williams Commented Mar 18 at 15:24
- First upgrade your maven-surefire-plugin version... second you have mixed up versions for junit -jupiter and junit-jupiter-param... should be the same... – khmarbaise Commented Mar 18 at 20:57
- @JohnWilliams yes they are in the same class. khmarbaise I did as you suggested, the test no longer failed but did not run. The reason it did not run is in the answer below. So sorry I wasted your time! – Daltin Commented Mar 19 at 6:35
1 Answer
Reset to default 0Okay, this is embarrassing. Here is the issue, a typo. I discovered it by logging in my @beforeEach method and then seeing where a successful run worked and a non successful run failed. Since the beforeEach never ran I started looking very carefully at the run command. It was a lowercase c:
// naughty command: mvn -Dtest=Lab5bTests#testAllSubclassesSetPackaging test
// proper command: mvn -Dtest=Lab5bTests#testAllSubClassesSetPackaging test
So since it never ever ran the test I just re-typed the command and found the error.
Thanks for watching! Who invented case sensitivity anyway? Ok, not as bad as white-space sensitive, but still...
Oh, and never trust AI to get case sensitivity correct! It does most of the time, but it taught me a lesson on this one!