Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automate the functional testing in yii2?

I use the codecept functional testing for test my APIs in yii2.I put the arguments hardcoded for testing like this

use tests\codeception\backend\FunctionalTester;
$I = new FunctionalTester($scenario);
$I->wantTo('Check when authenticated');
$I->sendPOST('/login', ['password' => '11111111', 'email'=>'[email protected]']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('"result"');
$I->seeResponseContains('"message"');
$I->haveHttpHeader('Accept','application/json');
$I->seeResponseContains('"message":"OK"');

I wanted to give that arguments while I running the test case by codecept run functional loginCept or save that arguments in one file and assign to the test case when I run the test.How should I achieve this?

like image 225
Anway Kulkarni Avatar asked Aug 28 '15 13:08

Anway Kulkarni


People also ask

What is functional test in Jira?

Functional test verifies scenarios from a user's perspective. It is similar to acceptance test but instead of communicating via HTTP it is filling up environment such as POST and GET parameters and then executes application instance right from the code.

What are fixtures in Yii?

The main purpose of fixtures is to set up the environment in an unknown state so that your tests run in an expected way. Yii provides a near fixture framework. A key concept of the Yii fixture framework is the fixture object. It represents a particular aspect of a test environment.

Is automated functional testing right for You?

Automated functional testing is, in a way, the best of both worlds—it brings to the table the benefits that automation provides to all kinds of tests, along with the functional testing ethos of putting the user’s needs first.

What is the difference between unit testing and functional testing?

Unit testing verifies that specific units are working, such as an exhaustive test of all your model's methods. Functional testing verifies common application scenarios as if a user was acting them out, but using web browser emulation. Acceptance testing is identical to functional testing but actually runs the tests through a web browser.


1 Answers

You can create a file in path/to/your/project/tests/codeception/config called let's say params.php. Then add params to the newly created file:

<?php
    return [
        'login.email' => '[email protected]', 
        'login.password' => '111111'
    ];

In your path/to/your/project/tests/codeception/config/config.php put this:

<?php
    return [
        'components' => [
            ...
        ],
        'params' => require(__DIR__ . '/params.php'),
    ];

Use it in your test code the same way you call params in a regular Yii application. It doesn't matter whether it is unit, functional etc.

Yii::$app->params['user.login'];
like image 175
Nikolay Traykov Avatar answered Oct 08 '22 22:10

Nikolay Traykov