[ 
https://issues.apache.org/jira/browse/SUREFIRE-1621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16752324#comment-16752324
 ] 

Alex Chachanashvili commented on SUREFIRE-1621:
-----------------------------------------------

If I change the sample project's test file to have public class and public 
method I get following:
{code:java}
~/Code/MavenJUnit5Test ᐅ mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< MavenJunit5Test:achacha.test.maven >-----------------
[INFO] Building achacha.test.maven 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 
achacha.test.maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ 
achacha.test.maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ 
achacha.test.maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory 
/Users/achacha/Code/MavenJUnit5Test/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ 
achacha.test.maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to 
/Users/achacha/Code/MavenJUnit5Test/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ 
achacha.test.maven ---
[INFO] Surefire report directory: 
/Users/achacha/Code/MavenJUnit5Test/target/surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running test.SampleTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec <<< 
FAILURE!
test.SampleTest.testAlwaysFails() Time elapsed: 0.002 sec <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:40)
at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:35)
at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:137)
at test.SampleTest.testAlwaysFails(SampleTest.java:10)


Results :

Failed tests: test.SampleTest.testAlwaysFails(): expected: <true> but was: 
<false>

Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.688 s
[INFO] Finished at: 2019-01-25T08:47:26-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal 
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on 
project achacha.test.maven: There are test failures.
[ERROR]
[ERROR] Please refer to 
/Users/achacha/Code/MavenJUnit5Test/target/surefire-reports for the individual 
test results.
[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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please 
read the following articles:
[ERROR] [Help 1] 
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
{code}
Which is expected since the test is simple assertTrue(false).

 

So just changing the visibility of class and method to public kicks off the 
tests.  This is the issue, JUnit5 has to work with package scope class and test 
method.

> package-private class/method supported in JUnit5 is not executed
> ----------------------------------------------------------------
>
>                 Key: SUREFIRE-1621
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1621
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: JUnit 5.x support
>    Affects Versions: 3.0.0-M3
>         Environment: Java openJDK11, Maven 3.6.0
>            Reporter: Alex Chachanashvili
>            Priority: Major
>         Attachments: MavenJUnit5Test.tar.gz
>
>
> Test classes/methods have to be made pubic in order for maven/surefire to 
> execute them.
>  
> Following will not execute (DebugTest.java) with surefire but will work with 
> IntelliJ, eclipse, Gradle, etc that support JUnit5:
>  
> {code:java}
> class DebugTest {
>      @Test
>      void failAlways() { assertTrue(false); }
> }
> {code}
>  
> However changing it to following will work with Surefire but cause IDEs to 
> flag public scope that can be changed to package-private:
>  
> {code:java}
> public class DebugTest {
>      @Test
>      public void failAlways() { assertTrue(false); }
> } 
> {code}
>  
> JUnit 5 is supposed to support package-private declaration for test classes 
> and test methods and IDEs like IntelliJ and eclipse are suggesting this, 
> creating issues for people writing new tests that are not aware of the 
> surefire anomaly.  Also automatic code cleanup in some IDEs are changing the 
> tests to be package-private and causing them to no longer run.
>  
> Package-private tests are running correctly inside the IDEs and via Gradle, 
> but being skipped with Maven+Surefire.
>  
> from POM (basically a simple java project) 
> {code:java}
> <build>
>    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
>   <plugins>
>      <plugin>
>        <groupId>org.apache.maven.plugins</groupId>
>        <artifactId>maven-surefire-plugin</artifactId>
>        <version>3.0.0-M3</version>
>      </plugin>
>    </plugins>
>  </build>
> {code}
>  
> and in dependencies: 
> {code:java}
> <dependencies>
> ...
>   <dependency>
>      <groupId>org.junit.jupiter</groupId>
>      <artifactId>junit-jupiter-api</artifactId>
>      <version>5.3.2</version>
>      <scope>test</scope>
>    </dependency>
>    <dependency>
>      <groupId>org.apache.maven.plugins</groupId>
>      <artifactId>maven-surefire-plugin</artifactId>
>      <version>3.0.0-M3</version>
>      <scope>test</scope>
>    </dependency>
> </dependencies>
> {code}
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to