You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-Introduction.md
+17-20Lines changed: 17 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,17 +14,17 @@ Let's review the listed testing paradigms in reverse order.
14
14
15
15
### Acceptance Tests
16
16
17
-
How does your client, manager, or tester, or any other non-technical person, know your site is working? She opens the browser, enters the site, clicks on links, fills the forms, and sees the proper pages as a result. She has no idea of the framework, database, web-server, or programming language you are using. If she sees improper behavior, she will create a bug report. Still this person has no idea why the application didn't work as expected.
17
+
How does your client, manager, or tester, or any other non-technical person, know your site is working? By opening browser, accessing a site, clicking on links, filling the forms, and actually seeing the contant on a web page. That person has no idea of the framework, database, web-server, or programming language you use or why application did not behave as it was expected.
18
18
19
-
Acceptance tests can cover standard but complex scenarios from a user perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors.
19
+
Acceptance tests can cover standard but complex scenarios from a user's perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors.
20
20
21
-
Please, note that **any site** can be covered with acceptance tests. Even if you use a very custom CMS or framework.
21
+
Please, note that **any web site** can be covered with acceptance tests. Even if you use a very custom CMS or framework.
@@ -37,29 +37,28 @@ $I->see('Thank you for Signing Up!');
37
37
* can be run on any website
38
38
* can test javascript and ajax requests
39
39
* can be shown to your clients and managers
40
-
*the most stable: less affected by changes in source code or technologies.
40
+
* most stable in support: less affected by changes in source code or technologies.
41
41
42
42
#### Cons
43
-
* fewer checks can lead to false-positive results
44
43
* the slowest: requires running browser and database repopulation.
44
+
* fewer checks can lead to false-positive results
45
45
* yep, they are really slow.
46
+
* not stable in execution: rendering and javascript issues, can lead to unpredicted results.
46
47
47
48
48
49
### Functional Tests
49
50
50
-
Let's say your application is tested by a technically advanced guy. He also opens the browser, enters the site, clicks links and submits forms, but when an error occurs he can report to you the exception that was thrown, or check the database for expected values. This guy already knows some aspects of your application, and by knowing that his tests can cover more technical details.
51
+
What if we could check our application without running it on a server? In this way we could see detailed exceptions on errors, have tests running faster, and check database for values we expect. That's a are what functional tests are for.
51
52
52
-
Functional tests are run without browser emulation. For functional tests you emulate a web request and submit it to your application. It should return to you a response. You can make assertions about the response, and also access the application's internal values.
53
+
For functional tests you emulate a web request ($_GET, $_POST variables) and send it into your application which returns HTML response. Inside a test you can make assertions about the response, also you can check the data was succesfully stored into database.
53
54
54
-
For functional tests your application should be prepared to be run in test mode. For frameworks like Symfony2, Symfony1, or Zend, it's easy to start an application in test mode.
55
-
56
-
Codeception provides connectors to several popular PHP frameworks, but you can write your own.
55
+
For functional tests your application should be prepared to be run in test environment. Codeception provides connectors to several popular PHP frameworks, but you can write your own.
Only the developer understands how and what is tested here. It can be either unit or integration tests, but they are limited to check one method per test.
88
-
89
-
The only difference between unit tests and integration tests is that a unit test should be run in total isolation. All other classes or methods should be replaced with stubs.
86
+
Testing pieces of code before coupling them together is highly important as well. This way you can be sure that some deeply hidden feature still works, even it was not touched by functional or acceptance tests. This also proves you produced stable and testable code.
90
87
91
88
Codeception is created on top of [PHPUnit](http://www.phpunit.de/). If you have experience writing unit tests with PHPUnit you can continue doing so. Codeception has no problem executing standard PHPUnit tests.
*fast as hell (well, in the current example, you still need database repopulation).
110
+
*fastest (well, in the current example, you still need database repopulation).
114
111
* can cover rarely used features.
115
112
* can test stability of application core.
116
113
* you can only be considered a good developer if you write them :)
117
114
118
115
#### Cons
119
116
120
117
* doesn't test connections between units.
121
-
*most unstable: very sensitive to code changes.
118
+
* unstable in support: very sensitive to code changes.
122
119
123
120
## Conclusion
124
121
125
-
Despite the wide popularity of TDD, few PHP developers ever write automatic tests for their applications. The Codeception framework was developed to make the testing actually fun. It allows writing unit, functional, integration, and acceptance tests in one style.
122
+
Despite the wide popularity of TDD, not all PHP developers ever write automatic tests for their applications. The Codeception framework was developed to make the testing actually fun. It allows writing unit, functional, integration, and acceptance tests in one style.
126
123
127
124
It could be called a BDD framework. All Codeception tests are written in a descriptive manner. Just by looking in the test body you can get a clear understanding of what is being tested and how it is performed. Even complex tests with many assertions are written in a simple PHP DSL.
Copy file name to clipboardExpand all lines: docs/02-GettingStarted.md
+26-27Lines changed: 26 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,20 @@
2
2
3
3
Let's take a look into Codeception architecture. We assume that you already [installed](http://codeception.com/install) it, and bootstrapped your first test suites. Codeception has generated three of them: unit, functional, and acceptance. They are well described in the previous chapter. Inside your __/tests__ folder you will have three config files and three directories with names corresponding to these suites. Suites are independent groups of tests with a common purpose.
4
4
5
-
## Actors (Guys)
5
+
## Actors
6
6
7
-
One of the main concepts of Codeception is representation of tests as actions of a person. By default we call this person a Guy (but you may choose different naming on bootstrap). We have a CodeGuy, who executes functions and tests the code. We also have a TestGuy, a qualified tester, who tests the application as a whole, with knowledge of its internals. And a WebGuy, a user who works with our application through an interface that we provide.
7
+
One of the main concepts of Codeception is representation of tests as actions of a person. We have a UnitTester, who executes functions and tests the code. We also have a FunctionalTester, a qualified tester, who tests the application as a whole, with knowledge of its internals. And a AcceptanceTester, a user who works with our application through an interface that we provide.
8
8
9
-
Each of these Guys are PHP classes along with the actions that they are allowed to do. As you can see, each of these Guys have different abilities. They are not constant, you can extend them. You can create new Guys If you like, but one Guy belongs to one suite. You can see the Guy classes inside the suite directories.
9
+
Each of these Actors are PHP classes along with the actions that they are allowed to do. As you can see, each of these Actors have different abilities. They are not constant, you can extend them. One Actor belongs to one testing suite.
10
10
11
-
Guy classes are not written, they are generated by the build command:
11
+
Actor classes are not written but generated from suite configuration. When you change configuration actor classes are **rebuilt automatically**.
12
+
13
+
If Actor classes are not created or updated as you expect, try to generate them manually with `build` command:
12
14
13
15
```
14
16
$ php codecept.phar build
15
17
```
16
18
17
-
Guy classes are generated from suite configuration. When you change configuration guy classes will be rebuilt automatically.
A Scenario always starts with Guy class initialization. After that, writing a scenario is just like typing `$I->` and choosing a proper action from the auto-completion list.
38
+
A Scenario always starts with Actor class initialization. After that, writing a scenario is just like typing `$I->` and choosing a proper action from the auto-completion list.
38
39
39
40
Let's sign in to our site. We assume that we have a 'login' page where we are getting authenticated by login and password. Then we are moved to a user page, where we see the text `Hello, %username%`. Let's look at how this scenario is written in Codeception.
40
41
41
-
```php
42
+
```php
42
43
<?php
43
-
$I = new WebGuy($scenario);
44
+
$I = new AcceptanceTester($scenario);
44
45
$I->wantTo('log in as regular user');
45
46
$I->amOnPage('/login');
46
47
$I->fillField('Username','davert');
@@ -50,32 +51,32 @@ $I->see('Hello, davert');
50
51
?>
51
52
```
52
53
53
-
Before we execute this test, we should make sure that the site is running on a local web server. Open the `tests/acceptance.suite.yml` file and replace the URL with the URL of your web application:
54
+
Before we execute this test, we should make sure that the site is running on a local web server. Let's open the `tests/acceptance.suite.yml` file and replace the URL with the URL of your web application:
54
55
55
56
```yaml
56
57
config:
57
58
PhpBrowser:
58
59
url: 'http://myappurl.local'
59
60
```
60
61
61
-
If you don't have a web server running, you can use the [PHP Built-in Web Server](http://php.net/manual/en/features.commandline.webserver.php) which is available in PHP 5.4.
62
-
63
-
After you set the proper URL, you can run this test with the command:
62
+
After we configured utl we can run this test with `run` command:
64
63
65
64
``` bash
66
65
$ php codecept.phar run
67
66
```
68
67
69
-
In the output you should see:
68
+
Here is the output we should see:
70
69
71
70
``` bash
72
-
Suite acceptance started
73
-
Trying log in as regular user (SigninCept.php) - Ok
The actions in Guy classes are taken from modules. With the `build` command described above, Codeception emulates multiple inheritance. Modules are designed to have one action performed with one method. According to the [DRY principle](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself), if you use the same scenario components in different modules, you can combine them and move them to a custom module. By default each suite has an empty module, which can extend Guy classes. They are stored in the ___helpers__ directory.
118
+
The actions in Actor classes are taken from modules. Generated Actor classes emulate multiple inheritance. Modules are designed to have one action performed with one method. According to the [DRY principle](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself), if you use the same scenario components in different modules, you can combine them and move them to a custom module. By default each suite has an empty module, which can be used to extend Actor classes. They are stored in the ___support__ directory.
118
119
119
120
## Bootstrap
120
121
121
-
Each suite has its own bootstrap file. It's located in the suite directory and is named `_bootstrap.php`. It will be executed before each test.
122
-
123
-
Write any setup preparations for the suite there.
122
+
Each suite has its own bootstrap file. It's located in the suite directory and is named `_bootstrap.php`. It will be executed before test suite.
124
123
125
124
## Test Formats
126
125
@@ -175,7 +174,7 @@ To generate JUnit XML output you can provide `--xml` option, and `--html` for HT
175
174
$ php codecept.phar run --steps --xml --html
176
175
```
177
176
178
-
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be store in `tests/_log/` directory.
177
+
This command will run all tests for all suites, displaying the steps, and building HTML and XML reports. Reports will be store in `tests/_output/` directory.
179
178
180
179
And to learn all available options:
181
180
@@ -202,4 +201,4 @@ There are plenty of useful Codeception commands.
202
201
203
202
## Conclusion
204
203
205
-
We took a look into the Codeception structure. Most of the things you need were already generated by the `bootstrap` command. After you have reviewed the basic concepts and configurations, you can start writing your first scenarios.
204
+
We took a look into the Codeception structure. Most of the things you need were already generated by the `bootstrap` command. After you have reviewed the basic concepts and configurations, you can start writing your first scenarios.
0 commit comments