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

[JUnit] Use AssumptionFailed to mark scenarios/steps as skipped #1142

Merged
merged 1 commit into from
Jun 12, 2017

Conversation

brasmusson
Copy link
Contributor

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

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality). Since the --allow-started-ignored option is only deprecated it is a non-breaking change.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly (the help for the junit options).

Copy link
Contributor

@mpkorstanje mpkorstanje left a 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);
}
Copy link
Contributor

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);
}
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@brasmusson
Copy link
Contributor Author

However I don't quite understand why exceptions from the before and after hooks are not used? Should they not fail the test?

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.

@mpkorstanje
Copy link
Contributor

Yes. I think we should reconsider that. Perhaps by wrapping all errors in something like junits MultipleFailureException construction. However looking at the scale of that change I think that is best done separately.

@brasmusson
Copy link
Contributor Author

Now all step exceptions are collected and at the end of the test case notified on the pickleRunnerNotifier (similarly to using ErrorCollectors in JUnit). The type of notifications are controlled by the result of the test case, so if the first step failed and the second is undefined, both will be notified using fileTestFailure (also in non-strict mode) since the test case as a whole get the status failed. It is not obviously the best solution, but it seems reasonable.

In a way it is consistent to the behaviour of an ErrorCollector when I both had a failing assert and added a AssumptionViolatedException to it - both were notified using fileTestFailure, but it is unlikely that someone have expected using an ErrorCollector like that.

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.
@brasmusson brasmusson force-pushed the junit-assumption-failed-for-skipped branch from e52a9a6 to 8512b10 Compare June 12, 2017 17:01
@brasmusson brasmusson merged commit 8512b10 into master Jun 12, 2017
brasmusson added a commit that referenced this pull request Jun 12, 2017
@brasmusson brasmusson deleted the junit-assumption-failed-for-skipped branch June 12, 2017 17:22
@lock
Copy link

lock bot commented Oct 25, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants