Codeception: Dependencies useless on running single test

Created on 22 Sep 2017  路  10Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

We have a bug test suite which takes a lot of time to finish.
There are some tests that depend on each other (e.g. a test for creating an entity requires another test to register a user and verify a new user)

As the hole test suite takes a lot of time I want to run a specific test only (e.g. creating an entity) but everything I tried results in failure as the depend tests don't get executed.

In general Codeception is configured to run everything on ./vendor/bin/codecept run.
So to run only specific SpotStatsBuildCest which depends on others I tried the following:

Try 1:
./vendor/bin/codecept run SpotStatsBuildCest

Suite 'SpotStatsBuildCest' could not be found

Try 2:
./vendor/bin/codecept run --fail-fast ./test/integration/cest/SpotStatsBuildCest.php

Integration Tests (3) --------------------
S SpotStatsBuildCest: Run peak calculation job 
S SpotStatsBuildCest: Send peak success calculation notification mail 
S SpotStatsBuildCest: Send peak failed calculation notification mail 
---------------------------------------------------------------------

Try 3:
Added a @group SpotStatsBuildCest to the class and
./vendor/bin/codecept run --fail-fast --group SpotStatsBuildCest

[Groups] SpotStatsBuildCest

Integration Tests (3) --------------------
S SpotStatsBuildCest: Run peak calculation job 
S SpotStatsBuildCest: Send peak success calculation notification mail 
S SpotStatsBuildCest: Send peak failed calculation notification mail 
---------------------------------------------------------------------

How can I run only this specific cest (+ dependencies)?

ENHANCEMENT

Most helpful comment

Yes, this would be a really nice feature to have.

I will try to implement this, but I don't know when I will have time for it - it could take a few months.

All 10 comments

Please could we add something like that? :-) My testing crew would love that feature...

Yes, this would be a really nice feature to have.

I will try to implement this, but I don't know when I will have time for it - it could take a few months.

Neither beforeSuite() work when running single test

I'm having issues with this too - in my case I'm running the failed tests, but they're being skipped because the testLogin upon which they depend hasn't been run.

I would like for CodeCeption to either run the dependencies, even if not specified - or in the case of running failed tests (which I realise is hard to differentiate from any other group) to assume dependencies which are not included in the run have passed.

Maybe adding a --force parameter that ignores dependencies could be an option too!

Ignoring dependencies doesn't help in any way. There is a reason why a test has it and it's a requirement for this test. If your test does not have such a requirement you better don't mark it with dependent tests

So I have a test that adds X component to a system and tests if it was saved, then I have another test that checks that configures X and stores it, and another one that checks that settings were properly stored.

Thing is that I might be back and forth doing changes on the 3rd test but I can't run it alone because it depends on #1 and #2 on a full test, but during development I would really like that dependencies were ignored.

Here's my use case: my tests are never dependent on another test running. I've got bootstrap code and factories for that.

I mostly use test dependencies for saying "This depends on LoginCest" because if LoginCest failed - there's no point running the rest of the tests.

Another option (in addition to my previosu suggestion about runnign the dependnecies even if they're not selected) would be to have a new attribute "@runFirst LoginCest" so it'll always make sure that test has been run before running the current test.

@marc-mabe For your Try 3, did you try adding all the tests it depends on to that same group as well? I tried that with a really small test and it ran with the correct depends.
I think your Try 1 can't be found because you have to say the suite, and with the whole filename.

codecept run <suitename> SpotStatsBuildCest.php

Even if that works, having @depends guarantee that the other tests will run (or something of the sort) would be really nice...

any news about that? I got stuck on same... would be nice to run single test with dep, once that I'm with a hundred of them :)

Was this page helpful?
0 / 5 - 0 ratings