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

Fix test cases execution time in reports #825

Closed
wants to merge 6 commits into from
Closed

Fix test cases execution time in reports #825

wants to merge 6 commits into from

Conversation

clicman
Copy link

@clicman clicman commented Jan 13, 2015

This is bug fix for test steps execution time. It was fired fireTestStarted event after test was performed.
I was moved event at the start of step execution. Now timings calculated right.

In tests I was just removed fireTestStarted execution verification because it not performed in that places.

clicman referenced this pull request in allure-framework/allure-cucumberjvm Jan 13, 2015
@brasmusson
Copy link
Contributor

This PR does not only correct the test steps execution time. It does also change one invariant; that a testStarted notification always is followed by a testFinished notification. With the PR a testStarted notification is sometimes followed by a testIgnored notification (for Undefined and Pending steps in non-strict mode). The questing is, do all RunListeners handle that a testStarted notification is followed by a testIgnored notification? What do you say @clicman? It's possible that the original intent behind not fire the testStarted notification until in the result method, was to ensure that either a testStarted notification and a testFinished notification was fired, or a testIgnored (its impossible to determine that a step is pending until in the result method).

When changing the invariant that a testStarted is followed by a testFinished is changed then the cucumber.runtime.junit.SanityChecker must be updated accordingly. Now it will trigger a failure when a testStarted is not folloed by a testFinished (hence the broken build for this PR).

When the testStarted is fired from the match method, I really thing there should be a test case that verifies that it actually is fired there.

@clicman
Copy link
Author

clicman commented Jan 18, 2015

@brasmusson, I`m not familiar with jUnit internals and just waited for reaction form person who could expalin me it :)

The questing is, do all RunListeners handle that a testStarted notification is followed by a testIgnored notification?
I`ve not faced problems with it. Standard jUnit listener works good.

When changing the invariant that a testStarted is followed by a testFinished is changed then the cucumber.runtime.junit.SanityChecker must be updated accordingly. Now it will trigger a failure when a testStarted is not folloed by a testFinished (hence the broken build for this PR).

Where SanityChecker used? In which projects/cases? I only can see it in picocontainer tests. I want determine what ele can be tested after SanityChecker update/

When the testStarted is fired from the match method, I really thing there should be a test case that verifies that it actually is fired there.
Ok. This is clear.

@brasmusson
Copy link
Contributor

@clicman I'm actually not familiar with SanityChecker, it looks as it was added as an internal utility to find problems in the JUnit integration. I don't find it used in any other place than in the picocontainer tests.

@clicman
Copy link
Author

clicman commented Jan 18, 2015

@brasmusson ok. I`ll update this PR soon with updated SanityChecker

@clicman
Copy link
Author

clicman commented Jan 18, 2015

  • SanityChecker was updated.
  • Tests not updated. Have no idea how to test it. And probably it should not be covered by separate test case.

@brasmusson
Copy link
Contributor

@clicman If you pull brasmusson@2e20deb from my clicman-junit-fire-test-started branch, you get a test case checking that testStarted is fired from the match method. I also improved the SanityChecker to check that testIgnored is fired for the latest fired testStarted.

@clicman
Copy link
Author

clicman commented Jan 21, 2015

Sorry for delay. To use RunListener in pair with Description - the better way, i like it. Thank you for test, now I undrstand how mocking works. I will update this PR ASAP.

sbt-sidochenko-vv added 2 commits January 21, 2015 14:03
Let the SanityChecker check that a received testIgnored event is for
the latest received testStarted event. Add a test that verifies that
the JUnitReporter.match method fires a testStarted event.
 clicman-junit-fire-test-started
if (ignoredStep) {
executionUnitNotifier.fireTestIgnored();
}
executionUnitNotifier.fireTestFinished();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only fireTestFinished() on the executionUnitNotifier (all others are on the stepNotifier), now the scenario (or in JUnit terms the test suite) will not be finished. The log for the picocontainer tests visualize this clearly (line 5758).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Stupid commit. Will revert it.

@clicman
Copy link
Author

clicman commented Jan 21, 2015

So I will not push any commits into this PR. Will commit if only it will fix reason which will deny merge to master.

@clicman
Copy link
Author

clicman commented Jan 22, 2015

@brasmusson should testFinished events fire for Ignored/skipped scenarios?

Sanity checker outputs this:

START  Scenario: An undefined step
  START  Given something undefined(Scenario: An undefined step)
  IGNORE Given something undefined(Scenario: An undefined step)
IGNORE Scenario: An undefined step
END    Scenario: An undefined step

START  Scenario: A pending step
  START  Given something pending(Scenario: A pending step)
  IGNORE Given something pending(Scenario: A pending step)
IGNORE Scenario: A pending step
END    Scenario: A pending step

As result we have two records in surefire xml for scenario finishing.

  <testcase name="Scenario: second" classname="Scenario: second" time="0">
    <skipped/>
  </testcase>
  <testcase name="Scenario: second" classname="Scenario: second" time="0"/>

@brasmusson
Copy link
Contributor

@clicman Whether testFinished should be fired for ignored/skipped scenarios, is a really good question. I recon that the answer depends on how common listeners like:

  • maven surefire
  • ant's junit task
  • Eclipse
  • IDEA

reacts when testFinished is fired versus when in is not fired for ignored/skipped scenarios (and maven surefire seems not to react well when it is fired).

The change that testFinished should always fire were introduced a couple of years ago. It is hard to see today the specific rational for that change (except that it make the SanityChecker's matching of testStarted and testFinished possible).

@clicman
Copy link
Author

clicman commented Jan 22, 2015

@brasmusson Okay. Now I understand problem background. Actually it doesn`t not affect on my project, but timing does. Could you answer when this PR will merged to master. And how often cucumber-jvm releases? I want do determine when it will be possible to make a new release of allure cucmber-jvm adaptor.

clicman pushed a commit to allure-framework/allure-cucumberjvm that referenced this pull request Jan 22, 2015
…xed.

Do not merge into master until this PR will released or it will hide pendings at all!

Fix package name in META-INF
@brasmusson
Copy link
Contributor

@clicman Looking back, there have been a new Cucumber-JVM release every 2-3 months or so. Unfortunately I can't really say when this PR will be merged.

@aslakhellesoy
Copy link
Contributor

@brasmusson is this good to merge?

@brasmusson
Copy link
Contributor

@aslakhellesoy I think it comes down to a trade-off between accurate times versus a bit more reasonably run counts - from the perspective on listeners to the JUnit-notifications. For listeners to be able to calculate accurate executions times, this PR is necessary (sending both the start and finish notification after the step has executed make the time between the notification irrelevant with respect to the execution time of the step).

On the other hand receiving first a start notification and then a ignore notification is not what listeners are expecting (I assume that an ignore notification is sent by itself for @org.junit.Ignore annotated tests from JUnit). When I make one step pending in the Java-Calculator example and run it. Then Cucumber-JVM's step count is 1skipped, 1pending, 34passed.

Executing it in Eclipse without this PR makes Eclipse JUnit listener to report the run count "36/36 (3 skipped)" (I guess the extra skipped comes from the scenario for which both a skipped and a finished notification is sent). Apart from that "36/36" (the number of steps) seems as reasonable reporting.

Executing it with this PR makes the reported run count "38/36 (3 skipped)", it seems like the two steps for which both a start and a ignore notification is send is counted twice in the "38". "38/36 (3 skipped) is less reasonable than, "36/36 (3 skipped)", but "36/36 (2 skipped)" seems to me even more reasonable. In both cases the test tree view is the same (the pending and skipped step, as well as their scenario is marked as skipped).

In the end I think it is OK to prioritize the accuracy in execution time calculated from the notifications, and merge this PR.

@clicman
Copy link
Author

clicman commented May 30, 2015

Up.

@dhaerinck
Copy link

Think it's important this one is fixed. Using Cucumber-JVM with the Allure reporting tool to automate production testing, and using simple internal DSL instead, I can have accurate timings in my test case reports. Pity.

@0I0u3uk
Copy link

0I0u3uk commented Dec 21, 2015

Hey, guys, why don't accept this PR?

@clicman
Copy link
Author

clicman commented Feb 6, 2016

@brasmusson I see you have merge rights. Can you merge this pull request?

@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.

5 participants