1

I've been trying to run JUnit 5 tests with Maven Surefire. However, it doesn't seem like Surefire is running any tests at all, even though I do have some, and in the default directory, too.

This is the console output I'm getting: https://prnt.sc/ugo1xt

Here are the relevant parts of the pom.xml:

  <dependencies>
    <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter</artifactId>
       <version>5.7.0-M1</version>
       <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
      </plugin>
    </plugins>
  </build>


The surefire version is 3.0.0-M4.

I've tried pretty much any fix I could find on Google, although most of them seemed to be outdated. Any help would be greatly appreciated.

Cheers!

EDIT: Here's an example of my tests:

package bankprojekt;

import bankprojekt.verarbeitung.*;

import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

public class GirokontoTest {
    Girokonto gk;

    @BeforeEach
    void setup(){
        gk = new Girokonto();
        gk.einzahlen(500);
    }

    @AfterEach
    void teardown(){
        gk = null;
    }

    @Test
    void abhebenMitWaehrungswechsel(){
        try{
            gk.abheben(195.583, Waehrung.BGN);
        }
        catch (Exception e) {
            System.out.println(e);
        }

        assertEquals(400, gk.getKontostand());
    }

    @Test
    void einzahlenMitWaehrungswechsel(){
        gk.einzahlen(195.583, Waehrung.BGN);

        assertEquals(600, gk.getKontostand());
    }
}
marceggers
  • 13
  • 1
  • 4
  • Is the maven using the latest version 3.6.3? Sometimes the old maven version could be incompatible with the surefire plugin version. Also please refer to the following link for some common error troubleshooting, https://xspdf.com/resolution/51739978.html – Sreedhar S Sep 13 '20 at 21:18
  • Please show an example of your unit test? Furthermore you can use version 5.7.0 instead of 5.7.0-M1... – khmarbaise Sep 13 '20 at 22:11
  • @SreedharS Yes, I'm running Maven 3.6.3. Sadly, nothing from the link you sent seems useful :( – marceggers Sep 14 '20 at 12:38
  • @khmarbaise, switching to 5.7.0 sadly didn't work. Adding a basic example of my tests in the question. – marceggers Sep 14 '20 at 12:42
  • Can you make an example project on github.... – khmarbaise Sep 14 '20 at 13:19
  • @khmarbaise https://github.com/marc-eggers/prog3-sose2020 So, hier einmal mein Projekt. Sollte zugänglich sein. Danke, dass du dir die Zeit nimmst, einem armen Studentchen zu helfen! ;) – marceggers Sep 14 '20 at 15:10
  • You should keep the english language... – khmarbaise Sep 14 '20 at 15:44

1 Answers1

0

There are two things. First you should upgrade jacoco dependency to 0.8.5 otherwise it fails based on the JDK14 requirement. (Created an pull request to your repository). If those things are configured appropriately the result is this:

I would also recommend to upgrade maven-compiler-plugin to most recent version and also all other plugins.

As you can see you have WARNING's in your build which should be fixed and failing tests.

This build has been run on plain command line also with JUnit-Jupiter 5.7.0 which works perfectly.

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ prog3-sose2020 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/classes
[WARNING] /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java: /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java uses or overrides a deprecated API.
[WARNING] /Users/khmarbaise/ws-git-so/prog3-sose2020/src/main/java/bankprojekt/verarbeitung/Kunde.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ prog3-sose2020 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/khmarbaise/ws-git-so/prog3-sose2020/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ prog3-sose2020 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ prog3-sose2020 ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running bankprojekt.GirokontoTest
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.087 s <<< FAILURE! - in bankprojekt.GirokontoTest
[ERROR] bankprojekt.GirokontoTest.abhebenMitWaehrungswechsel  Time elapsed: 0.052 s  <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <448.87081188037814> but was: <400.0>
    at bankprojekt.GirokontoTest.abhebenMitWaehrungswechsel(GirokontoTest.java:31)

[INFO] Running bankprojekt.WaehrungTest
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 s - in bankprojekt.WaehrungTest
Kunde Mustermann, Max zerst�rt
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   GirokontoTest.abhebenMitWaehrungswechsel:31 expected: <448.87081188037814> but was: <400.0>
[INFO] 
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.792 s
[INFO] Finished at: 2020-09-14T17:50:43+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M4:test (default-test) on project prog3-sose2020: There are test failures.
[ERROR] 
[ERROR] Please refer to /Users/khmarbaise/ws-git-so/prog3-sose2020/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
khmarbaise
  • 92,914
  • 28
  • 189
  • 235