yii2 install, configure and run codeception tests - yii2

I'm writing this because yii2 official documentation is still not complete and codeception documentation itself refer to yii2 official docs..:).
I have some questions:
In my yii2 app root there is a directory "tests/codeception", this means that codeception is already installed in my project?
in vendor/yiisoft there is another codeception directory "yii2-codeception" what is it?
the documentation say to create a yii2_basic_tests database and to run a migration, but migration script create only a "migration" table, is it correct?
the integration with yii2 provide some web interface or I must run the tests from console scripts?
Someone can explain me how to install and configure codeception in yii2 basic app step by step?
Thank you
Alessandro

I am doing some like that:
composer global require "codeception/codeception=2.0.*" "codeception/specify=*" "codeception/verify=*"
And next:
ln -s ~/.composer/vendor/bin/codecept /usr/local/bin/codecept
Then I am available to do globally
codecept run

First make sure you read this a couple of times http://www.yiiframework.com/doc-2.0/guide-test-environment-setup.html
Afterwards the actual tests are easy to set up. Make sure you make the codecept command work like it says on the last line of the link above. After you install an Yii app you have to go to the tests folder and run
codecept build
to initialise the tests. Then run
codecept run
to run the actual tests.
You can run
codecept run --coverage-html
to get the code coverage for your project.
I have never got the acceptance testing working with code coverage but I got acceptance working without coverage and unit&functional with coverage.

Related

Running unit tests with Codeception in Yii2 project

Trying to setup remote Codeception Unit Tests in PhpStorm in a Yii2 project.
Using SSH I can log into the server go to the root directory of my Yii2 project and run :
> vendor/bin/codecept run unit
and the tests run.
I'm trying run these remote tests via PhpStorm, I've setup a Remote PHP CLI interpreter and I'm pointing to the Codeception library in my Yii2 project folder:
/var/www/vhosts/mydomain.com/httpdocs/yii2/vendor/bin/codecept
Test Runner points to:
/var/www/vhosts/mydomain.com/httpdocs/yii2/codeception.yml
Trying to run the tests the following command is executed:
> ssh://user#mydomain.com:22/opt/plesk/php/5.6/bin/php /root/.phpstorm_helpers/phpunit.php --no-configuration /var/www/vhosts/mydomain.com/httpdocs/yii2/tests
The process fails at it complains that it cannot find PHPUnit:
Process finished with exit code 1
Cannot find PHPUnit in include path (.:/opt/plesk/php/5.6/share/pear)
How do I get PhpStorm to look for PHPUnit in the yii2/vendor folder? Can I just tell PhpStorm to run a different command instead of this phpstorm_helpers? It seems that the documentation is out of date and the screenshots JetBrains provides are from a different version of PhpStorm, I'm running PhpStorm 2017.3
So after a LOT of digging, the issue was with the Run/Debug Configuration. Despite adding Codeception to the Test Frameworks section, clicking the run button still tried to execute a pure PHPUnit test.
To switch to run the test as Codeception, look at the top toolbar above the file tabs:
There you will be able to define various options:
Now under run you'll have additional options:
Choose the blue Codeception icon to run the test using Codeception instead of PHPUnit

How would I run integration tests from vivet/googleApi?

I am trying to work out how I would integrate this shared library from GitHub into my code, since it is a shared class library, for starters I just want to run the integration tests, but I cannot work out how go get the test runner to run them.
I created a console application in my main project and a reference to the GoogleMapsApiTest in the console but I am not sure how to call the tests from there to run them.
GoogleAPIClassLibrary
I had to download the gui test runner and build it from GitHub. Link to project
now I can at least run the tests, I am still not sure how to use the library but that should help at least see how it is supposed to work.
I was able to run the unit tests by downloading the NUnit source code at the link in my post and then browsing to the output dll of the class project, to load the tests apparently the gui-test runner is no longer available for download, so hopefully that will help someone else out if they run into a need for running tests in NUnit.

Visual Studio Team Services Building JSON Scripts

I'm currently building scripts using Selenium Builder (which saves files as JSON) and i'm having a hard time running these scripts on VSTS. My question specifically is, can Visual Studio Team Services build JSON scripts and tie them in with its C.I.? If so, which approach must I take in order to do this / make it possible?
Thanks!
Here is my steps for your reference:
Deploy your own private build agent by following this link.
Configure the required environment on the build agent like Selenium Driver, Firefox so that the testing can be run on the build agent.
Upload the json file generated by Selenium Builder into VSTS Repository.
Create a build definition with two Command Line tasks: The first one runs npm install command to install se-interpreter:
And the second one run se-interpreter command to run the test in json file:
Queue the build, you will see the test been executed during the build:

Tests failed when codecept run with report parameter

I installed yii2 basic template project. I did not change anything in source code. When I run default tests by codecept run command, all tests passed. When I run codecept with parameter --report, functional tests failed for submit login and submit contact form cest.
Did anyone have such a problem?
My env: Yii 2.0.12, PHP 7.1.2, Codeception 2.3.3
Codeception doesn't seem to have much documentation about the parameter --report, but it seems like you have to specify a custom reporter to use. Otherwise, you can use --html, --xml, etc for step by step reports
http://codeception.com/docs/02-GettingStarted#Reports

Why won't my NAnt builds run in Hudson?

My NAnt builds run fine locally on a developer machine, and locally on the command line of the Hudson server, but they will not run in my configured Hudson project.
The console output when I run a Build via the Hudson web UI is similar to the following :
Started by user anonymous [workspace]
$ sh -xe
C:\WINDOWS\TEMP\hudson8104357939096562606.sh
C:\WINDOWS\TEMP\hudson8104357939096562606.sh:
fork failed: no error [1] Archiving
artifacts Finished: SUCCESS
I have another project configured properly that runs fine so I know the NAnt plugin is setup properly in Hudson, and that NAnt is on the system path.
Can anyone suggest possible causes as to why this build won't run?
The problematic build may be configured to Execute a Shell script, rather than Execute a Windows Batch file.
Copy the command from the existing build step (the Execute Shell Script) and remove the step. Then add a new step to Execute a windows Batch File and paste the command.
Trigger the build and observe the results.
(I asked and answered this since it took me quite a while to figure out how I had mis-configured this particular build. Hopefully it'll save time or give ideas to other people trouble-shooting automation..)