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
It is recommended to have unit and functional testing set up per each bundle and acceptance tests for set globally. Unit and Functional tests will check that each bundle work as expected while acceptance tests will check the UI and work of a system as a whole.
41
+
From Symfony 4 onwards there will be a top-level `tests` directory instead of a separate `Tests` directory in each bundle.
42
+
So to save you from reconfiguration in the future, it is recommended place unit, functional, and acceptance test files
Continue to <a href="http://codeception.com/docs/07-BDD">Behavior Driven Development Guide »</a>
120
122
</div>
121
123
122
-
## Bundle Setup
124
+
## Functional Testing
123
125
124
-
Each bundle should have its own Codeception setup. To have test configuration for `AppBundle` you should run:
126
+
There is no need to use `WebTestCase` to write functional tests. Symfony functional tests are written in the same manner as acceptance tests but are executed inside a framework. Codeception has the [Symfony Module](http://codeception.com/docs/modules/Symfony) for it. To create a functional test suite, run:
This will create `tests` dir inside `src/AppBundle`.
131
-
132
-
### Functional Testing
133
-
134
-
There is no need to use `WebTestCase` to write functional tests. Symfony functional tests are written in the same manner as acceptance tests but are executed inside a framework. Codeception has `Symfony` module for it. It is a good idea to separate functional and unit tests so it is recommended to create a new test suite for AppBundle
Functional tests are written in the same manner as acceptance tests. They also use scenario and `$I` actor object. The only difference is how they are executed. To run tests as Symfony test you should enable corresponding module in functional suite configureation file `src/Appundle/tests/functional.suite.yml`. Probably you want Doctrine to be included as well. Then you should use this configuration:
132
+
Functional tests are written in the same manner as acceptance tests. They also use scenario and `$I` actor object. The only difference is how they are executed. To run tests as Symfony test you should enable corresponding module in functional suite configuration file `tests/functional.suite.yml`. Probably you want Doctrine to be included as well. Then you should use this configuration:
141
133
142
134
```yaml
143
135
class_name: FunctionalTester
144
136
modules:
145
137
enabled:
146
138
- Symfony:
147
-
app_path: '../../app'
148
-
var_path: '../../app'
139
+
app_path: 'app'
140
+
var_path: 'app'
149
141
- Doctrine2:
150
142
depends: Symfony
151
-
- \AppBundle\Helper\Functional
143
+
- \Helper\Functional
152
144
```
153
145
154
146
<divclass="alert alert-warning">
@@ -163,13 +155,13 @@ modules:
163
155
164
156
### API Tests
165
157
166
-
API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests for `ApiBundle` bundle you should create a suite for them
158
+
API Tests are done at functional testing level but instead of testing HTML responses on user actions, they test requests and responses via protocols like REST or SOAP. To create api tests, you should create a suite for them:
167
159
168
160
```
169
-
php bin/codecept g:suite api -c src/ApiBundle
161
+
php bin/codecept g:suite api
170
162
```
171
163
172
-
You will need to enable `REST`, `Symfony` and `Doctrine` module in `src/ApiBundle/tests/api.suite.yml`:
164
+
You will need to enable `REST`, `Symfony` and `Doctrine` module in `tests/api.suite.yml`:
173
165
174
166
```yaml
175
167
class_name: ApiTester
@@ -180,11 +172,11 @@ modules:
180
172
depends: Symfony
181
173
- Doctrine2:
182
174
depends: Symfony
183
-
- \ApiBundle\Helper\Api
175
+
- \Helper\Api
184
176
config:
185
177
- Symfony:
186
-
app_path: '../../app'
187
-
var_path: '../../app'
178
+
app_path: 'app'
179
+
var_path: 'app'
188
180
189
181
```
190
182
@@ -199,22 +191,22 @@ Symfony module actions like `amOnPage` or `see` should not be available for test
199
191
200
192
### Unit Testing
201
193
202
-
You should put your unit tests for AppBundle into `src/AppBundle/tests/unit`. It is done to not mix them with functional and API tests. To start unit test suite for `AppBundle` shoule be created:
194
+
Create a unit test suite with:
203
195
204
196
```
205
-
php bin/codecept g:suite unit -c src/AppBundle
197
+
php bin/codecept g:suite unit
206
198
```
207
199
208
-
Codeception is powered by PHPUnit so unit and integration test work in a similar manner. To genereate a plain PHPUnit test for `Foo` class inside `AppBundle` please run
200
+
Codeception is powered by PHPUnit so unit and integration test work in a similar manner. To genereate a plain PHPUnit test for `Foo` class, run:
209
201
210
202
```
211
-
php bin/codecept g:phpunit unit Foo -c src/AppBundle
203
+
php bin/codecept g:phpunit unit Foo
212
204
```
213
205
214
206
This generates a standard test inherited from `PHPUnit_Framework_TestCase`. For integration tests you may use Codeception-enhanced format which allows accessing services DI container, Doctrine, and others. You will need to enable Doctrine2 and Symfony module in `unit.suite.yml` config. Such integration test is extending `Codeception\Test\Unit` class and created by running:
215
207
216
208
```
217
-
php bin/codecept g:test unit Foo -c src/AppBundle
209
+
php bin/codecept g:test unit Foo
218
210
```
219
211
220
212
Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester` inside a test of `Codeception\Test\Unit`.
@@ -223,15 +215,3 @@ Actions of Symfony and Doctrine2 modules will be accessible from `$this->tester`
Continue to <ahref="http://codeception.com/docs/05-UnitTests">Unit Testing Guide »</a>.
225
217
</div>
226
-
227
-
228
-
### Running it all together
229
-
230
-
Codeception allows to execute all tests with different configurations in one runner. To execute all tests at once with `codecept run` you should include bundle configurations into global configuration file `codeception.yml` in the root of a project:
231
-
232
-
```yaml
233
-
include:
234
-
- src/*Bundle
235
-
```
236
-
237
-
Then running codeception tests from root directory will execute tests from all bundles as well as acceptance tests.
0 commit comments