[
https://issues.apache.org/jira/browse/SUREFIRE-1621?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16750847#comment-16750847
]
Karl Heinz Marbaise commented on SUREFIRE-1621:
-----------------------------------------------
[~achacha] The given dependency to maven-surefire-plugin is not needed (to be
honest it's simply wrong, cause you should never have a maven plugin as
dependency) nor the definition of the {{testSourceDirectory}} makes sense,
cause it's the default. Can you please check via {{mvn dependency:tree}} if you
are not by accident using JUnit 4 in your module? Cause that you can execute
the tests if your make the class public sounds like that?
I have the same a very similar scenario except for JDK 8.
The following differences I have in contradiction to the above scenario: One
class which looks like the following:
{code:java}
class StringUtilsTest {
@Test
void isBlankShouldBeTrueForNull() {
assertThat(StringUtils.isBlank(null)).isTrue();
}
@Test
void isBlankShouldBeTrueForEmpty() {
assertThat(StringUtils.isBlank("")).isTrue();
}
}
{code}
This tests are being executed fine(So I can't acknowledge the above scenario).
Unfortunately I have the following class:
{code:java}
class PreconditionTest {
@Nested
@DisplayName("XYZ Tests")
static class XYZNotNullTests {
@Test
void requireNotNullShouldReturnIAE() {
assertThrows(IllegalArgumentException.class, () -> requireNotNull(null,
"test"));
}
}
@Nested
@DisplayName("ABC Tests")
static class ABCTests {
@Test
void requireNotEmptyShouldReturnIAE() {
assertThrows(IllegalArgumentException.class, () -> requireNotEmpty(null,
"Null message"));
}
}
}
{code}
This class is completely not seen in the test results nor being executed
somehow. In Eclipse / IntelliJ I can run the tests fine.
{code}
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ utils ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running ....utils.ClassUtilsTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.164 s
- in ....utils.ClassUtilsTest
[INFO] Running ....utils.StringUtilsTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s
- in ....utils.StringUtilsTest
[INFO]
{code}
I have tried to run the tests with this plugins:
{code:xml}
<plugin>
<groupId>de.sormuras.junit</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
{code}
which executed the all tests without any issue.
> 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
>
> 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)