Basic Template CodeCeption Test Can only run one by one


(Patrick) #1
  1. create yii2-basic template application

  2. run test




$ composer create-project --prefer-dist yiisoft/yii2-app-basic basic

$ composer global require "codeception/codeception=2.0.*"

$ composer global require "codeception/specify=*"

$ composer global require "codeception/verify=*"

$ cd basic/tests

$ ../vendor/bin/codecept run   -------------- run all test cases.



result as follows:




Codeception PHP Testing Framework v2.1.2

Powered by PHPUnit 4.8.6 by Sebastian Bergmann and contributors.


Functional Tests (4) -------------------------------------------------------------------------------------------------------------------------

Ensure that about works (AboutCept)                                                                                                     Ok

Ensure that contact works (ContactCept)                                                                                                 Ok

Ensure that home page works (HomeCept)                                                                                                  Ok

Ensure that login works (LoginCept)                                                                                                     Ok

----------------------------------------------------------------------------------------------------------------------------------------------


Acceptance Tests (4) -------------------------------------------------------------------------------------------------------------------------

Ensure that about works (AboutCept)                                                                                                     Ok

Ensure that contact works (ContactCept)                                                                                                 Ok

Ensure that home page works (HomeCept)                                                                                                  Ok

Ensure that login works (LoginCept)                                                                                                     Ok

----------------------------------------------------------------------------------------------------------------------------------------------


Unit Tests (4) ----------------------------------------------------------------------------------------------------------------------------------

Test contact (tests\codeception\unit\models\ContactFormTest::testContact)                                                                  Ok

Test login no user (tests\codeception\unit\models\LoginFormTest::testLoginNoUser)                                                          Ok

Test login wrong password (tests\codeception\unit\models\LoginFormTest::testLoginWrongPassword)                                            Ok

Trying to test login correct (tests\codeception\unit\models\LoginFormTest::testLoginCorrect)... PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 32 bytes) in /home/workspace/basic/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php on line 121

<pre>PHP Fatal Error 'yii\base\ErrorException' with message 'Allowed memory size of 1073741824 bytes exhausted (tried to allocate 32 bytes)' 


in /home/workspace/basic/vendor/myclabs/deep-copy/src/DeepCopy/DeepCopy.php:121


Stack trace:

#0 [internal function]: yii\base\ErrorHandler-&gt;handleFatalError()




Obviously unit test got something wrong, out of memory

however, if I run unit test directly,




$cd tests

$ ../vendor/bin/codecept run unit  -------------------- only run unit tests



Unit test can pass. WHY is this happen?





Codeception PHP Testing Framework v2.1.2

Powered by PHPUnit 4.8.6 by Sebastian Bergmann and contributors.


Unit Tests (4) ----------------------------------------------------------------------------------------------------------------------------------

Test contact (tests\codeception\unit\models\ContactFormTest::testContact)                                                                  Ok

Test login no user (tests\codeception\unit\models\LoginFormTest::testLoginNoUser)                                                          Ok

Test login wrong password (tests\codeception\unit\models\LoginFormTest::testLoginWrongPassword)                                            Ok

Test login correct (tests\codeception\unit\models\LoginFormTest::testLoginCorrect)                                                         Ok

-------------------------------------------------------------------------------------------------------------------------------------------------




Time: 47.82 seconds, Memory: 472.75Mb


OK (4 tests, 14 assertions)




similar symptom happens with yii2-advanced template.


(Patrick) #2

we may also notice the unit test cost very long time


 Time: 47.82 seconds, Memory: 472.75Mb 

47.82 seconds. 99% of the test are cost by last unit test.

memory cost is huge, as compared with this little skeleton web-app.


(Patrick) #3

finally, the test executed fast enough, it turns out to be the codeception version problem.

Yii2 can only stick to version 2.0.*

6702

2015_0909_0400_002.jpg

if using 2.1.* then above strange problem (long executing time) occur.


(Patrick) #4

its’ because function codeception/specify will do cloning of objects in order to achieve isolation.

Deepcopy fails for Yii2 objects when codeception version does not match. memory burns out, and cause test case fail.

The ‘lucky’ success (run unit test alone),is also strange that too much memory is consumed and execution time are much longer then normal.

time blocks at ‘deepcopy’


(Nenad Z) #5

I have this exact problem when using Codeception 2.1.6

Is there any other option for solving this problem except using older version of Codeception ?


(Softark) #6

[color="#006400"]/* Moved from "General" to "Testing" */[/color]


(Alexander Makarov) #7