Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@MichalPawlicki
Copy link
Contributor

Include durations of individual tests in JUnit reports generated by sbt. Addresses #4803.

This is still WIP and I'd like to get some feedback before I move forward. Basically, my idea is to:

  • Add a duration field to TestSuccess and TestFailure.
  • Time an assertion in ZTest#apply and pass the duration to TestSuccess/TestFailure.
  • In ZTestEvent#from, pass the duration to ZTestEvent.

A couple of questions about this approach:

  • Is it ok to always time tests, or should we give users the option to disable this?
  • Are TestSuccess and TestFailure the right places to store duration?
  • Timing the assertion in ZTest#apply produces expected results, but maybe there's a better place to do it?

@CLAassistant
Copy link

CLAassistant commented Apr 18, 2021

CLA assistant check
All committers have signed the CLA.

@adamgfraser
Copy link
Contributor

I think this use case is already addressed by the timed test aspect.

@MichalPawlicki MichalPawlicki force-pushed the feature/zio_test_report_execution_times branch 3 times, most recently from 0251609 to 526daf1 Compare April 20, 2021 21:17
@MichalPawlicki
Copy link
Contributor Author

Thanks, timed does the job, I changed the implementation so that duration is extracted from the timing annotation.

I still have a problem though, the duration of a failing test is reported as 0. (I rebased on master so my branch already includes this fix: #4988). The timing annotation seems to disappear before the event is reported to sbt. Could it be caused by suite transformations, e.g. the one here:

e => Spec.test(label, failure(e), TestAnnotationMap.empty),
?

@adamgfraser
Copy link
Contributor

@MichalPawlicki No that line of code only runs if the suite can't be created at all (e.g. the suite of tests was supposed to be generated based on contents from a file and couldn't be loaded). The time of failing tests is being reported correctly in tests with SBT so I would look in the implementation of the JUnit runner itself.

@MichalPawlicki
Copy link
Contributor Author

So basically, this seems to work. When I break a random test, annotate it with timed, and run it with the sbt testOnly task,
sbt generates a report in target/test-reports which includes the failure with a duration:

<testcase classname="zio.test.TestAspectSpec" name="around evaluates tests inside context of Managed" time="0.208">
  <failure message="No Exception or message provided"/>
</testcase>

I'm just having problems with making it work in ZTestFrameworkSpec. I'll look further into this.

@MichalPawlicki MichalPawlicki force-pushed the feature/zio_test_report_execution_times branch from 526daf1 to 71668e7 Compare May 11, 2021 19:09
@MichalPawlicki
Copy link
Contributor Author

I spent some time debugging it, but I can't get the assertion in ZTestFrameworkSpec to work. I guess there's some subtle difference between running testOnly (or test) from sbt and what happens in ZTestFrameworkSpec. The only thing that I found is that sbt test creates a TaskDef with a SuiteSelector (like here), but changing this in ZTestFrameworkSpec still doesn't help. At this point TestAnnotationMap no longer contains the timing annotation for a failed test .

(Note: this is not an issue with JUnit runner, but with JUnit test reports generated by default by sbt).

Any idea what else might be wrong? Would it be an option to merge the change in ZTestEvent without adding a test in ZTestFrameworkSpec, so that users could use it?

@adamgfraser
Copy link
Contributor

@MichalPawlicki That's fine.

@MichalPawlicki MichalPawlicki force-pushed the feature/zio_test_report_execution_times branch from 71668e7 to 4ca23b6 Compare May 16, 2021 08:23
@MichalPawlicki MichalPawlicki marked this pull request as ready for review May 16, 2021 08:24
@MichalPawlicki MichalPawlicki changed the title WIP feat(zio-test): include duration in JUnit test reports feat(zio-test): include duration in JUnit test reports May 16, 2021
@MichalPawlicki
Copy link
Contributor Author

@adamgfraser this is ready for review. 🙂 In the end, I added a test, but just for a passing spec.

Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

@adamgfraser adamgfraser merged commit 74ccb3a into zio:master May 19, 2021
@MichalPawlicki MichalPawlicki deleted the feature/zio_test_report_execution_times branch May 22, 2021 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants