Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-2189

Tests in src/main/java are not detected

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.1.2
    • None
    • None
    • Java 17, with or without JPMS

    Description

      There are sometimes reasons to put JUnit tests under src/main/java next to production code. Surefire cannot detect these tests and runs only tests under src/test/java.

      I tried to set testClassesDirectory to target/classes. That causes surefire to run tests under src/main/java, but then tests under src/test/java are ignored. Changing testClassesDirectory also causes weird module loading exceptions in a bigger project with more dependencies.

      If you are curious why anyone would put tests in production code, here are my reasons:

      1. I want to run all tests in the background after the app starts in dev environment. Since the tests rarely fail, this lets me shorten edit-test-run cycle into edit-run cycle.
      2. I want to visually annotate app UI that has associated tests.
      3. I want to run tests in production environment as a sanity check.
      4. I want to check compatibility between the app and its environment. This could be done with ordinary code, but structuring it as JUnit tests is convenient and results in clean code. I want to run these tests via surefire too to make sure they aren't already failing in dev environment.
      5. Keeping tests under src/main/java makes them more salient during development. Tests hidden under src/test/java tend to be forgotten during refactoring or when the tested code changes.

      Attachments

        Activity

          People

            Unassigned Unassigned
            robert.vazan Robert Važan
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: