Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert changes to method search algorithm #3600

Closed
rdehuyss opened this issue Dec 11, 2023 · 14 comments
Closed

Revert changes to method search algorithm #3600

rdehuyss opened this issue Dec 11, 2023 · 14 comments

Comments

@rdehuyss
Copy link

rdehuyss commented Dec 11, 2023

Hi there, I'm Ronald, the creator of JobRunr. When upgrading my dependencies to 5.10.1 from 5.10.0, I noticed a breaking change which was not declared in the release notes.

When using tests and inheritance (which I do for testing JobRunr against different DB's), I noticed that @Disabled was not taking into account anymore in v5.10.1 whereas that was the case in v5.10.0.

Steps to reproduce

Please see https://github.com/rdehuyss/junit-issue-disabled

If you run the test JUnitTest3, you notice that it fails. If you downgrade to 5.10.0, all is well again.

Context

  • Used versions (Jupiter/Vintage/Platform): JUnit Jupiter
  • Build Tool/IDE: both maven and gradle, Intellij
@rdehuyss
Copy link
Author

rdehuyss commented Dec 11, 2023

Never mind, it has apparently been declared in 5.10.1... Three questions:

  • is there a place where I can find the reasoning behind this?
  • and would this change (if following semver and breaking) not validate a new major version change?
  • as I used this feature a lot, how to solve this (instead of copying the @Disabled over and over)?

Thanks!

@rdehuyss rdehuyss changed the title JUnit 5.10 breaks inheritance when using @Disabled JUnit 5.10.1 breaks inheritance when using @Disabled Dec 11, 2023
@rdehuyss
Copy link
Author

Reopening as this really breaks a lot for me... Would you accept a PR for an annotation @DisabledAndInherited?

@rdehuyss rdehuyss reopened this Dec 11, 2023
@sbrannen
Copy link
Member

Never mind, it has apparently been declared in 5.10.1... Three questions:

What was declared in the release notes for 5.10.1 is that the documentation for the existing behavior was improved.

As far as I know, we did not intentionally change the behavior for @Disabled with regard to inheritance.

Are you saying your sample project demonstrates a change in behavior for @Disabled between 5.10.0 and 5.10.1?

@rdehuyss
Copy link
Author

Hi @sbrannen! Thanks for getting back to me so quickly!

Are you saying your sample project demonstrates a change in behavior for @disabled between 5.10.0 and 5.10.1?

Yes

With 5.10.0, the JUnitTest3 is green, upgrading to 5.10.1 changes it to red.

@rdehuyss
Copy link
Author

Relates to #3462

@rdehuyss
Copy link
Author

Hi @sbrannen - where you able to verify the example project showing the change with @Disabled?

@marcphilipp
Copy link
Member

Thanks for the reproducer! I can confirm that the behavior has indeed changed:

public abstract class AbstractJUnitTest {

    @Test
    protected void someTestMethod() {
        System.out.println("This should not run as disabled by AnstractJUnitTest2");
        throw new RuntimeException("Should not be thrown");
    }

    @Test
    protected void anotherTestMethod() {
        System.out.println("This should run");
    }
}
public abstract class AbstractJUnitTest2 extends AbstractJUnitTest {

    @Override
    @Disabled
    protected void someTestMethod() {
        super.someTestMethod();
    }
}
public class JUnitTest3 extends AbstractJUnitTest2{
}

In 5.10.0, JUnit3Test.someTestMethod is skipped, whereas 5.10.1 executes it. I think this is caused by 1752389.

@sbrannen
Copy link
Member

If you rewrite AbstractJUnitTest2 as follows, someTestMethod() is properly disabled.

public abstract class AbstractJUnitTest2 extends AbstractJUnitTest {

	@Disabled
	@Test
	@Override
	protected void someTestMethod() {
		super.someTestMethod();
	}

}

If I recall correctly, we have never claimed in JUnit Jupiter that a @Test method can be overridden and still be considered a test method if the override does not redeclare @Test.

So, I consider that the expected behavior (or at lest the behavior we originally intended).

In light of that, I actually consider it a bug that the scenario without @Test worked before.

@sbrannen sbrannen changed the title JUnit 5.10.1 breaks inheritance when using @Disabled JUnit 5.10.1 breaks inheritance when using @Disabled Dec 15, 2023
@sbrannen
Copy link
Member

Here's a simplified all-in-one reproducer.

class DisabledReproTests extends AbstractJUnitTest {

	@Disabled
	// @Test
	@Override
	void someTestMethod() {
		super.someTestMethod();
	}

}

abstract class AbstractJUnitTest {

	@Test
	void someTestMethod() {
		throw new RuntimeException("Boom!");
	}

}

As has been pointed out, this scenario results in a test failure (unless you uncomment // @Test).

However, I think that should actually result in "no tests found", since DisabledReproTests overrides someTestMethod() without redeclaring that it is a @Test method.

So, let's discuss that behavior within the team.

@sbrannen sbrannen changed the title JUnit 5.10.1 breaks inheritance when using @Disabled JUnit 5.10.1 breaks inheritance when using @Disabled on a @Test method Dec 15, 2023
@marcphilipp marcphilipp added this to the 5.10.2 milestone Dec 15, 2023
@sbrannen
Copy link
Member

After further analysis, I realized that @Disabled never had any influence on the scenarios discussed here, and I'll change the title to reflect that.

With 5.10.0 (and earlier versions), if you override a @Test method in a subclass and do not annotate the overriding method with @Test, you have effectively already disabled the test method.

The reason is that the overriding method will no longer be discovered as a @Test method, and consequently @Disabled has no effect. So you can safely delete @Disabled in such scenarios.

However, the change in 5.10.1 is in fact a regression since JUnit no longer "sees" the overriding method and therefore detects the overridden method in the super class as a valid @Test method which should not be the case.

In light of that, we have scheduled this for 5.10.2 and will investigate how best to address this in org.junit.platform.commons.util.ReflectionUtils.findAllMethodsInHierarchy(...).

@sbrannen sbrannen changed the title JUnit 5.10.1 breaks inheritance when using @Disabled on a @Test method JUnit 5.10.1 no longer detects that a method has been overridden if the overriding method is filtered prematurely Dec 15, 2023
@sbrannen sbrannen changed the title JUnit 5.10.1 no longer detects that a method has been overridden if the overriding method is filtered prematurely JUnit 5.10.1 no longer detects that a method is overridden if the overriding method is filtered prematurely Dec 15, 2023
@sbrannen
Copy link
Member

For the sake of clarity for anyone following this issue...

In 5.10.0, JUnit3Test.someTestMethod is skipped,

In 5.10.0, it is not discovered as a test method and therefore is also not reported as skipped.

I think this is caused by 1752389.

That's correct.

@rdehuyss
Copy link
Author

You guys are the best! Thanks for all the investigation...

chemicL added a commit to reactor/reactor-core that referenced this issue Jan 5, 2024
…3685)

Overridden methods from `GenericBoundedElasticThreadPerTaskShedulerTest`
were not previously executed but are now due to [a regression in
junit](junit-team/junit5#3600 (comment)).

This change restores the original behaviour of assumptions and excludes
such tests using the parent class' facility.
@sbrannen sbrannen self-assigned this Jan 6, 2024
@sbrannen
Copy link
Member

sbrannen commented Jan 7, 2024

Team Decision:

  • In 5.10.2: revert the changes to our method search algorithm introduced in conjunction with #3498, #3500, and #3534.
  • In 5.11.0: address the issue originally raised in #3498 when we resolve #3553.

@sbrannen sbrannen changed the title JUnit 5.10.1 no longer detects that a method is overridden if the overriding method is filtered prematurely JUnit 5.10.1 no longer detects that method is overridden if overriding method is filtered prematurely Jan 14, 2024
@sbrannen sbrannen changed the title JUnit 5.10.1 no longer detects that method is overridden if overriding method is filtered prematurely Revert changes to method search algorithm Jan 14, 2024
sbrannen added a commit that referenced this issue Jan 15, 2024
sbrannen added a commit that referenced this issue Jan 15, 2024
…lgorithms"

This reverts commit a670d10.

See #3534
See #3553
See #3600

(cherry picked from commit 2f05a7c)
sbrannen added a commit that referenced this issue Jan 15, 2024
This commit reverts the functional changes from commit 64ed21a and
disables the associated tests for the time being.

See #3498
See #3500
See #3553
Closes #3600

(cherry picked from commit c2f49f6)
@findepi
Copy link

findepi commented Feb 6, 2024

With 5.10.0 (and earlier versions), if you override a @Test method in a subclass and do not annotate the overriding method with @Test, you have effectively already disabled the test method.

that's correct, but sometimes not desirable, especially that IDEs like IntelliJ make it easy to override a test method, but do not add @Test.
from that perspective, 5.10.1 had a nice behavior of overrides no longer being ignored. Is there a longer term plan to make 5.10.1's behavior available via configuration? is there an issue i should track?

KotlinBuild pushed a commit to JetBrains/kotlin that referenced this issue Mar 20, 2024
See junit-team/junit5#3600

In 5.10.1, the behavior changed and overridden tests now also need
to be annotated with a test annotation.
KotlinBuild pushed a commit to JetBrains/kotlin that referenced this issue Mar 20, 2024
See junit-team/junit5#3600

In 5.10.1, the behavior changed and overridden tests now also need
to be annotated with a test annotation.
KotlinBuild pushed a commit to JetBrains/kotlin that referenced this issue Mar 21, 2024
See junit-team/junit5#3600

In 5.10.1, the behavior changed and overridden tests now also need
to be annotated with a test annotation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants