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
Provide annotation that a test currently fails by given circumstances #551
Comments
I really like this idea, it just makes sense to have the option to bake the assumption that the test fails into the enable/disable logic. Straight-up winner on that front. But I'm wondering, whether it isn't still too close to Is there a way to implement this as a kind of "modifier" on @NotWorking
@DisabledOnOs(MAC)
void test() {
// ...
} Then One weird trick that could work would be:
That's... probably not a good idea? 🤷🏾 |
I only had a brief look at how |
Just found: #468 (Abort tests if URL is unreachable) which also goes into this direction |
Thanks for looking into it, @Marcono1234. This is the relevant code: /**
* Evaluate all {@link ExecutionCondition} extensions registered for the
* supplied {@link ExtensionContext}.
*
* @param context the current {@code ExtensionContext}
* @return the first <em>disabled</em> {@code ConditionEvaluationResult},
* or a default <em>enabled</em> {@code ConditionEvaluationResult} if no
* disabled conditions are encountered
*/
public ConditionEvaluationResult evaluate(ExtensionRegistry extensionRegistry, JupiterConfiguration configuration, ExtensionContext context) {
// @formatter:off
return extensionRegistry.stream(ExecutionCondition.class)
.filter(configuration.getExecutionConditionFilter())
.map(condition -> evaluate(condition, context))
.filter(ConditionEvaluationResult::isDisabled)
.findFirst()
.orElse(ENABLED);
// @formatter:on
} It makes obvious that there's no way for us, as one of many So we're stuck with |
Two thoughts... NameWe need to see whether there's a better name: I have something like ConfigurationThe extension I introduce in #505 also needs to act on a test's thrown exceptions. It allows configuration of which specific exceptions (e.g. I also noticed how the extension handles assumptions and think that makes a lot of sense. Yet, it could be made configurable as well. Come to think of, does #505 correctly handle failing assumption? |
The reason why I wanted to avoid such name containing "expect" is that it makes it sound like the developer intentionally wants the exception. While actually the developer only acknowledges that there is currently a bug which prevents the test from succeeding. I am afraid that when you want to include the evaluation of the execution ("if so, what happens if it fails/succeeds?") in the name, you always risk making it sound like the extension is an alternative for |
I thought about the name a bit more. We basically want to communicate three things:
I talked to a few people at DevoxxUK just now to get their input. Two proposals:
Thoughts? |
I like the wording with |
I don't like I also don't like Honestly, I like your original idea,
|
To keep this issue and the related PR from stalling, I'm just gonna make the call and say the extension should be named @Marcono1234 Are you ok with that? Or at least ok enough to finish the PR? 😉 If not, that's ok, too, just let us know and we'll finish it. |
I still think that "expected", especially in the context of unit tests, might erroneously give the impression that it is desired that the test fails, while it is actually merely "acknowledged", see also my comment #551 (comment) above. However, I am not strongly opposed to this, so if you want to call it Also, if you think it is easier, feel free to work on the pull request yourself (or use it as base for your changes); but please let me know in that case beforehand. |
I understand, but I still think it's the best option.
I'll take another look and let you know over there.
I don't think I'll do that, but good to know there's the option (you never know when boredom presents itself 😉). Will let you know if that happens. 👍🏾 |
I just came across this project implementing a similar idea: https://github.com/MartinWitt/GithubIssue Probably not that relevant for this implementation, but maybe interesting nonetheless that someone else had a similar idea, and how they implemented it. Edit: Not sure if that extension works properly though; looks like |
As opposed to JUnit Jupiter's `@Disabled` annotation, this extension executes the annotated test and then effectively flips the result: * failed ~> ignored * passed ~> failed This ensures that a temporarily disabled test will get discovered once the reason for being disabled no longer holds, so it can/must be re-enabled by removing `@ExpectedToFail`. PR: #676
Creating an issue as base for the PR for a
@NotWorking
annotation. Text comes from the PR by @Marcono1234Often tests fail due to a bug in the tested application or in used dependencies.
Traditionally such a test method would be annotated with JUnit's
@Disabled
.However, this has the following disadvantages when the bug causing the test failure
is fixed:
time after the bug has been fixed, adding no value for the project
@NotWorking
tries to solve these issues. Unlike@Disabled
it still executes theannotated test method but aborts the test if a test failure or error occurs.
However, if the test is executed successfully the
@NotWorking
annotation will causea test failure because the test is working.
This lets the developer know that they have fixed a bug (possibly by accident) and that
they can now remove the
@NotWorking
annotation from the test method.It is therefore recommended to prefer using
@NotWorking
over@Disabled
in most cases; exceptions for this are for example 'flaky' tests.
Important: This annotation is not intended as a way to mark test methods
which intentionally cause exceptions.
Such test methods should use JUnit's
assertThrows
or similar means to explicitlytest for a specific exception class being thrown by a specific action.
The text was updated successfully, but these errors were encountered: