2014-06-11

How to Run Test in Codeception?

In this article we are going to see the Test running command. From my previous article we know about initiating test case. Now its time to run. I will write commands for running in different ways.

In command prompt (change directory to root of the project where we have the codeception.yml) write those (In all cases I have use 2 type commands , a codeception with phar , and codeception with composer)

1. Run All Tests :
A: php codecept.phar run
B: ./vendor/codeception/codeception/codecept run
2. Run Only a Particular Suit :
A: php codecept.phar run <suitName>
Example  : php codecept.phar run acceptance
B: ./vendor/codeception/codeception/codecept run <suitName>
3. Run Only a particular test file under a particular suit
A: php codecept.phar run <suitName> <testFileName>
Example : php codecept.phar run acceptance regWithEmailCept.php
B: ./vendor/codeception/codeception/codecept run <suitName>  <testFileName>

Options :
And Now, with Every Run Command We can use different options. Day by day, the number of options are getting increased. I am mentioning some necessary options that we may use.

1. To see test running step by step , we have to add –steps in the command . (I am giving example for only this option, others are similar to this.) , From previous example if we want to add the steps option, the command will be
php codecept.phar run acceptance regWithEmailCept.php –steps

2. To run tests with no stepping use --silent

3. To use custom path for configuration file (suite specific YMLs) . we need to add --config or –c , like
--config = “path to configuration yml”

4. To debug test and get scenario output we need to use –debug or –d

5. To run Tests in Groups, we need to add --group or –g , like
--group=”name of the group”

6. To run tests with skipping group use --sg or --skip-group=”group name to skip”

7. To run tests by skipping test suit use –skip or –s. (we need to mentioned suit name like as group)

8. To run tests with specific Environment use --env=”desire environment values ”

9. To keep the test running (no finish with exit code) we use --no-exit

10. To stop after first fail , we use –f or --fail-first

11. To display any custom help message use –h or --help=”our desired message”

12. To stop all message showing, –q or --quiet

13. To skip interactive questioning use --no-interaction or -n

Coverage Options :
1. Run with code coverage  use  --coverage
2. Generate CodeCoverage HTML /XML /text report (in path) use 
--coverage-html
--coverage-xml
--coverage-text

Report /output Options :
1. To show output in compact style use –report
2. Generate html/xml/Tap/json log use
--html 
--xml
--tap
--json
3. To use/hide colors in output , use –colors or --no-colors
4. For Ansi or no ansi output use, -- ansi /--no-ansi

Thanks…:)