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

Is the test order within one file (one describe block) guaranteed? #2901

Closed
Nasicus opened this issue Dec 5, 2018 · 1 comment
Closed

Is the test order within one file (one describe block) guaranteed? #2901

Nasicus opened this issue Dec 5, 2018 · 1 comment

Comments

@Nasicus
Copy link

Nasicus commented Dec 5, 2018

So this may not even be a Cypress specific thing but since I'm using Cypress I still think it's bes to ask here.

I'ts a very simply question:

Is the test order within one file (one describe block) guaranteed?

Why do I ask that?

We have quite a lot of database dependent tests.
Because of this we often have to seed our database data within tests.

Now let's assume I have the following tests:

describe('My database tests', () => {
  // this is only done once for all tests in this block
  before(() => {
    seedUsersInDatabase();
  });

  it('Get users', () => {
    // expect 10 users
   });

  it('Remove users', () => {
    // expect 5 users removed
   });
});

Maybe you already see why the question poppep up.

If it's guaranteed that the tests within a describe block are always executed in the same order, I can seed the database with before. However if the order is not guaranteed I'd need to change it to beforeEach.

I personally assumed the order is guaranteed and therefore wrote only the before. The main reason for this is by the way: Performance! Seeding a database sometimes takes quite the time (even if it's just 100ms, it sums up if you have a lot of tests).

@jennifer-shehane
Copy link
Member

The tests will run in order, although we don't recommend you rely on the state of a previous test for your next test. Also, if one test fails (say your second test), all of the tests following may be affected or you may get false positives / negatives due to the state not being changed in that failed tests.

In the future, we recommend questions relating to how to use Cypress be asked in our community chat. Issues in our GitHub repo are reserved for potential bugs or feature requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants