codeception

What is the purpose, and proper use of wantTo() in Codeception?


I'm using the testing framework Codeception to do BDD. I understand the idea of wanting something, but I don't understand what the function does.

$I->wantTo('Understand what this method does!');

Solution

  • http://codeception.com/docs/03-AcceptanceTests#Comments

    Commands like amGoingTo, expect, expectTo help you in making tests more descriptive.

    $I->wantTo('Understand what this method does!');
    

    will be rendered as * I want to understand what this method does! in verbose output.

    Update 2022-11-16:

    My original answer was incorrect, wantTo is not a comment method, it renames test method in the output.

    Example:

    I created very simple Cest class:

    <?php
    
    class ExampleCest
    {
        public function provideExample(CliGuy $I)
        {
        }
    }
    

    When I ran it, I got the following output:

    Cli Tests (1) --------------------------------------------
    U ExampleCest: Provide example (0.00s)
    ---------------------------------------------------------
    

    but after adding $I->wantTo('change test name!'); to method: I got the following output:

    Cli Tests (1) --------------------------------------------
    U ExampleCest: Change test name! (0.00s)
    ---------------------------------------------------------
    

    The benefit of wantTo is that it allows to use characters not permitted in method names or different formatting than automatically generated.

    I looked up if wantTo has any documentation and all I found was old blog post using examples in class-less Cept format (which is deprecated and is likely to be removed in Codeception 6).

    <?php
    
    $I = new TestGuy($scenario);
    $I->wantTo('log in to site');
    $I->amOnPage('/');
    $I->click('Login');
    $I->fillField('username', 'admin');
    

    In Cept format wantTo had better purpose, because it didn't override anything, but provided additional information next to file name.