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.

[Question] Scoped test suite contexts

See original GitHub issue

I need to test a pretty typical password-reset page. The page is only available after going through a relatively long flow: Go to sign-in page, click password reset link, enter email, click submit, open email, click link in email, arrive on tested page.

Multiple elements must be tested on this page: do a visual regression test, make sure the right error helpers appear, etc. Each element needs its own test().

Multiple “suites” of tests need to be executed, some of which end by actually performing the password reset, which invalidates the page’s URL and makes it unavailable to further testing.

Here are the options considered so far:

  • Using a non-scoped fixture, the initial flow would be repeated for each individual test, which is not efficient and would blow up testing time.
  • Using a worker-scoped fixture, the initial flow is only done once, but can’t be redone if the reset page is invalidated. Any test that runs after a password reset is performed will fail.
  • Using a single test() with nested test.step()s works, but makes it impossible to selectively run specific steps (for instance using the VSCode extension).
  • Using test.beforeAll() to set up the flow requires a common page object to be provided by a worker-scoped fixture, so that it can be used by subsequent test()s. This solution doesn’t guarantee that the provided page is isolated and in a usable state. As it is shared across all tests, some might use it to sign in, then the password reset page would be unavailable. Relying on this sort of global, shared object will undoubtedly lead to test flakiness.

Is there anything obvious I’m missing? Having the ability to generate private, scoped, disposable contexts that can be used across a defined set of tests would be very helpful.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Aug 25, 2022

We don’t have plans to implement suite-scoped fixtures but let’s keep the issue open for some time to see if it gets enough upvotes.

0reactions
idmadjcommented, Aug 25, 2022

At this point I’m fairly confident that you pointed me towards the most optimal solution using the current capabilities.

You can prepare the page in beforeEach instead

This is not possible as the page needs to be prepared before the code in beforeAll (the logic in beforeAll depends on the page as prepared by the overriden fixture).

You don’t have to use built-in page fixture and can reference passwordResetPage variable directly.

I actually do want to use the logic from an overridden page fixture in beforeAll. From what I understand, I would need to repeat any code that’s in that fixture override into the beforeAll body to achieve that goal, which I’d rather avoid.

I believe you can turn passwordResetPage/‘signInPage’ in a worker fixture, something along these lines … Bear in mind though that such fixture are torn down only after all tests in the worker.

That wouldn’t work as each test would perform some navigation on the used page, meaning that subsequent tests wouldn’t necessarily begin from the same state.

This is another reason why I think the addition of group-scoped fixtures would be of great help. Generally, using beforeAll along with fixtures makes it hard to encapsulate and reuse code across a project as they ultimately use different paradigms despite serving similar purposes.

Let’s close this issue at this point as I think we’ve got to the bottom of the problem. I’d just like to add my voice to those who believe that group-scoped fixtures would bring significant benefit to the elaboration of more complex tests. Let me know if I should open a separate feature request issue.

Thanks a lot for your help and support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Scope: What's the Scope of a Unit Test? - Leading Agile
“Unit test scope” is a funny term. It seems to be the subject of all kinds of debate. Most of that debate is...
Read more >
Test organization with contexts - Test Double | Blog
Separating the contexts allows the scope of setup for one method or set of tests to be isolated from another. This is beneficial...
Read more >
Difference Between Test Plan, Test Strategy, Test Case, and ...
A Test Plan can be defined as a document that defines the scope, objective, and approach to test the software application. The Test...
Read more >
Spring Framework 3.2 RC1: New Testing Features
In this post we'll first take a look at some of the general new testing features in the Spring Framework, and then we'll...
Read more >
request scoped beans in spring testing - java - Stack Overflow
Now, on to your original problem. If you want to try registering the request scope with your test context, then have a look...
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