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

Does the if function work in codepcetion ? #4793

Closed
Roobix13 opened this issue Jan 30, 2018 · 4 comments
Closed

Does the if function work in codepcetion ? #4793

Roobix13 opened this issue Jan 30, 2018 · 4 comments

Comments

@Roobix13
Copy link

I am a bit confused, to understand why i will explain the problem im having.

Problem

Users enters a number, then there is a 'check' method to see if the number ( in this case room ) is available.
I made a simple if function but codeception just stops at the condition.
After the if condition, which results in true, it should chose another floor and pick another room to check if that is available.

`$I->wantTo('Pick a available room');

    $I->selectOption('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-level-select > div.input-select > select','1. Etage');

    $I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','107');
    $this->checkFavRoom($I);

    if ($I->see('ENTSCHULDIGUNG'))
    {
        $I->selectOption('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-level-select > div.input-select > select','2. Etage');
        $I->fillField('body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div.mod-desired-room__filter > div.js-build-desired-choose-room > div.grid.js-desired-room-choose > div > div > div:nth-child(1) > div > input[type="text"]','214');
        $this->checkFavRoom($I);

    }`

Shell output with -vvv

 I select option "body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-
 ready > div > div.mfp-content > div...","1. Etage"

 I fill field "body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div >...","107"

 I click "body > div.mfp-wrap.mfp-close-btn-in.mfp-auto-cursor.mfp-desired-room.mfp-ready > div > div.mfp-content > div > div > div > div...."

 I see "ENTSCHULDIGUNG"

 PASSED
@Roobix13 Roobix13 changed the title Does if work in codepcetion ? Does the if function work in codepcetion ? Jan 30, 2018
@Naktibalda
Copy link
Member

see is not a condition - it is an assertion. If see fails, it throws exception and execution of test stops.
If it succeeds, it doesn't return anything.

Using if in test is a bad practice (if it actually is a test), you should have 2 separate tests - one when room is available and another when it isn't.

@Roobix13
Copy link
Author

Roobix13 commented Jan 30, 2018

Okay that does make sense.
Thank you.

EDIT: The Problem is, One day the Room may be taken and one day the Room may not be taken.
So even if i make one test for a Taken room and one test for a available room, It will vary a lot of the times.

@Naktibalda
Copy link
Member

Don't run tests on live database.
Run tests on test database that you man mend in any way you like with Db module.

@DavertMik
Copy link
Member

...and don't use IFs inside tests. Tests should be predictable.
If your tests will fail you won't know is the problem in code, in room, or in moon phase. That's why run tests on predefined set of data. This way passing of a test will depend on the codebase only.

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

No branches or pull requests

3 participants