question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resources extension: Consider running tests sequentially when lifecycle methods have resources

See original GitHub issue

When tests and lifecycle methods share the same @Shared resource, they are forced to run sequentially, even if parallel tests have been enabled. This prevents methods from mutating the resource at the same time.

However, it is a common pattern in JUnit to save some data in a field from inside a lifecycle method. This is error-prone because if a resource is saved in a field by a @BeforeAll method, then the @Tests will run in parallel as they are not annotated with @Shared directly, and thus they are free to mutate the resource at the same time.

To prevent this, we should consider running all tests in a test class sequentially (including all @Nested classes) when the class has a lifecycle method with a @Shared parameter.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jbduncancommented, Nov 15, 2022

I like it! It makes it clear what the user should be doing instead.

0reactions
nipafxcommented, Nov 15, 2022

I think that’s ok. I’m editing the docs as we ~speak~ write - should I add this sentence?

Instead, use @Shared to reuse resources in multiple tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introduction to the Build Lifecycle - Apache Maven
If you want to run the unit tests, run test . This command executes each default lifecycle phase in order ( validate ,...
Read more >
List Of JUnit Annotations: JUnit 4 Vs JUnit 5
Annotations is a Java API that enables JVM to recognize the type of the method defined in the test class. There are 'lifecycles...
Read more >
JUnit 5 User Guide
The following test class demonstrates the use of @Test methods and all supported lifecycle methods. For further information on runtime semantics ...
Read more >
Test lifecycle - Grafana k6
The four distinct lifecycle stages in a k6 test are "init", "setup", ... The teardown function runs, postprocessing data and closing the test...
Read more >
DependsOn attribute - AWS CloudFormation
This dependency ensures that the policy is available throughout the resource's lifecycle. For example, imagine that you have a template with a deployment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found