8
8
## Test Cases
9
9
10
10
Every test needs a * test case* , or class that your tests extend. CodeIgniter 4
11
- provides a few you may use directly:
11
+ provides a few that you may use directly:
12
12
* ` CodeIgniter\Test\CIUnitTestCase ` - for basic tests with no other service needs
13
13
* ` CodeIgniter\Test\CIDatabaseTestCase ` - for tests that need database access
14
14
@@ -22,22 +22,25 @@ common to your test suites.
22
22
## Tests
23
23
24
24
All tests go in the ** tests/** directory. ** ci-module-tests** provides two generic
25
- subfolders for you ** unit** and ** database** but feel free to make your own. Each test file
26
- is a class that extends a ** Test Case** (see above) and contains methods for each individual
27
- test . These method names must start with the word "test" and should have descriptive names
25
+ subfolders for you, ** unit** and ** database** - but feel free to make your own. Each test file
26
+ is a class that extends a ** Test Case** (see above) and contains methods for the individual
27
+ tests . These method names must start with the word "test" and should have descriptive names
28
28
for precisely what they are testing: ` testUserCanModifyFile() ` ` testOutputColorMatchesInput() `
29
29
` testIsLoggedInFailsWithInvalidUser() `
30
30
31
+ Writing tests is an art, and there are many resources available to help learn how. Review
32
+ the links above and always pay attention to your [ Code Coverage] ( docs/COVERAGE.md ) .
33
+
31
34
### Database Tests
32
35
33
- ** ci-module-tests** provides a examples for migrating, seeding, and testing against a mock
36
+ ** ci-module-tests** provides examples for migrating, seeding, and testing against a mock
34
37
or live<sup >1</sup > database. The example files can be modified or replaced with your own:
35
38
* ** tests/_ support/Database/Migrations/create_test_tables.php**
36
39
* ** tests/_ support/Database/Seeds/ExampleSeeder.php**
37
40
* ** tests/_ support/Models/ExampleModel.php**
38
41
39
42
Be sure to modify the test case (or create your own) to point to your seed and migrations
40
- and include any additional steps in ` setUp() ` :
43
+ and include any additional steps to be run before tests in the ` setUp() ` method :
41
44
* ** tests/_ support/DatabaseTestCase.php**
42
45
43
46
<sup >1</sup > Note: If you are using database tests that require a live database connection you will need
@@ -47,6 +50,7 @@ repo by adding it to **.gitignore**.
47
50
48
51
### Session Tests
49
52
50
- Similar to the database test case, ** ci-module-tests** provides a test case pre-configured
51
- with the mock session class to make testing sessions easy:
53
+ Similar to database testing, ** ci-module-tests** provides a test case pre-configured
54
+ with the [ mock session class] ( https://codeigniter4.github.io/userguide/testing/overview.html#mocking-services )
55
+ to make testing sessions easier:
52
56
* ** tests/_ support/SessionTestCase.php**
0 commit comments