-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[JUnit] Use AssumptionFailed to mark scenarios/steps as skipped #1142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite follow all the changes to the JUnitReporter but it appears the tests are there and cover all cases.
# | Pickle Event | Junit Event | Test |
1 | TestCaseStarted | runNotifier.fireTestStarted | test_case_started_fires_test_started_for_pickle |
2a | TestStepStarted (hook) | ignored | |
2a | TestStepFinished (hook) | ignored | |
3a | TestStepStarted (step) | stepNotifier.fireTestStarted | test_step_started_fires_test_started_for_step |
3b | TestStepFinished (step) | notifyResult(stepNotifier) | test_step_finished_fires_only_test_finished_for_passed_step |
| | stepNotifier.fireTestFinished | test_step_finished_fires_assumption_failed_and_test_finished_for_skipped_step |
| | | test_step_finished_fires_assumption_failed_and_test_finished_for_pending_step_in_non_strict_mode |
| | | test_step_finished_fires_assumption_failed_and_test_finished_for_pending_step_in_strict_mode |
| | | test_step_finished_fires_assumption_failed_and_test_finished_for_undefined_step_in_non_strict_mode |
| | | test_step_finished_fires_failure_and_test_finished_for_undefined_step_in_strict_mode |
| | | test_step_finished_fires_failure_and_test_finished_for_failed_step |
4a | TestStepStarted (hook) | ignored | |
4b | TestStepFinished (hook) | ignored | |
5 | TestCaseFinished | notifyResult(stepNotifier) | test_case_finished_fires_only_test_finished_for_passed_step |
| | runNotifier.fireTestFinished | test_case_finished_fires_assumption_failed_and_test_finished_for_skipped_step |
| | | test_case_finished_fires_assumption_failed_and_test_finished_for_pending_step_in_non_strict_mode |
| | | test_case_finished_fires_assumption_failed_and_test_finished_for_pending_step_in_strict_mode |
| | | test_case_finished_fires_assumption_failed_and_test_finished_for_undefined_step_in_non_strict_mode |
| | | test_case_finished_fires_failure_and_test_finished_for_undefined_step_in_strict_mode |
| | | test_case_finished_fires_failure_and_test_finished_for_failed_step |
However I don't quite understand why exceptions from the before and after hooks are not used? Should they not fail the test?
|
||
public SkippedThrowable() { | ||
this(NotificationLevel.STEP); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor is not used. I guess it should be removed?
|
||
public UndefinedThrowable() { | ||
this(NotificationLevel.STEP); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This constructor is not used. I guess it should be removed?
} | ||
|
||
public SkippedThrowable(NotificationLevel scenarioOrStep) { | ||
super(String.format("This %s is skipped", scenarioOrStep.lowerCaseName()), null, false, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which version of java are we using? I'm seeing some java 7 stuff here and there but this is not defined present in the pom. Might be good to put this in there explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since v1.1.6 "JDK7 is required to build everything. Built jars should still work on JDK6" (see History.md). I would be a good idea to make it explicit in the pom.
The exceptions from before and after hooks will fail the test, through the result of the Test Case Event, which holds the worst result (created here) from all the steps and hooks (collected by ScenarioImpl) However, different from today only the worst exception will be notified on the pickleRunnerNotifier - maybe that should be reconsidered. |
Yes. I think we should reconsider that. Perhaps by wrapping all errors in something like junits |
f09e109
to
e52a9a6
Compare
Now all step exceptions are collected and at the end of the test case notified on the In a way it is consistent to the behaviour of an To get a clearer view of the end state of the JUnit module, I'm thinking of merging this after #1145 which also is affecting the notification logic. |
Since it is only after a step or scenario has been executed we can tell if it should be considered skipped in JUnit terms, TestAssumptionFailed notifications suits better than TestIgnored notifications. By using TestAssumptionFailed to mark scenarios/steps as skipped, TestStarted can always be fired before the scenario/step is executed, therefore the option --allow-stared-ignored is not longer needed.
e52a9a6
to
8512b10
Compare
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Send TestAssumptionFailed notifications instead of TestIgnored notifications to mark scenarios/steps as skipped.
Details
Since it is only after a step or scenario has been executed we can tell if it should be considered skipped in JUnit terms, TestAssumptionFailed notifications suits better than TestIgnored notifications.
By using TestAssumptionFailed to mark scenarios/steps as skipped, TestStarted can always be fired before the scenario/step is executed, therefore the option
--allow-stared-ignored
is not longer needed.Motivation and Context
By using TestIgnored notifications, the passing of the TestStarted had to be delayed until after the step has executed, which is both unexpected and an unnecessary complex solution. It also caused the need for the
--allow-stared-ignored
option (which adds more complexity).How Has This Been Tested?
In addition to the automatic tests of the junit module, I have experimented with the java-calculator example from within Eclipse and with maven.
Types of changes
--allow-started-ignored
option is only deprecated it is a non-breaking change.Checklist: