88## Test Cases
99
1010Every 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:
1212* ` CodeIgniter\Test\CIUnitTestCase ` - for basic tests with no other service needs
1313* ` CodeIgniter\Test\CIDatabaseTestCase ` - for tests that need database access
1414
@@ -22,22 +22,25 @@ common to your test suites.
2222## Tests
2323
2424All 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
2828for precisely what they are testing: ` testUserCanModifyFile() ` ` testOutputColorMatchesInput() `
2929` testIsLoggedInFailsWithInvalidUser() `
3030
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+
3134### Database Tests
3235
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
3437or live<sup >1</sup > database. The example files can be modified or replaced with your own:
3538* ** tests/_ support/Database/Migrations/create_test_tables.php**
3639* ** tests/_ support/Database/Seeds/ExampleSeeder.php**
3740* ** tests/_ support/Models/ExampleModel.php**
3841
3942Be 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 :
4144* ** tests/_ support/DatabaseTestCase.php**
4245
4346<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**.
4750
4851### Session Tests
4952
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:
5256* ** tests/_ support/SessionTestCase.php**
0 commit comments