Skip to content

Commit

Permalink
Merge pull request #1936 from jim-parry/docs/testing
Browse files Browse the repository at this point in the history
Docs: improve app testing writeup
  • Loading branch information
jim-parry authored Apr 11, 2019
2 parents 113f4ae + 9630400 commit 3701b57
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions user_guide_src/source/testing/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,38 @@ The Test Class
==============

In order to take advantage of the additional tools provided, your tests must extend ``\CIUnitTestCase``. All tests
are expected to be located in the **tests/** directory by default.
are expected to be located in the **tests/app** directory by default.

To test a new library, **Foo**, you would create a new file at **tests/TestFoo.php**::
To test a new library, **Foo**, you would create a new file at **tests/app/Libraries/FooTest.php**::

<?php namespace Tests;
<?php namespace App\Libraries;

class MyTests extends \CIUnitTestCase
class FooTest extends \CIUnitTestCase
{
public function testFooNotBar()
{
. . .
}
}

To test one of your models, you might end up with something like this in ``tests/app/Models/OneOfMyModelsTest.php``::

<?php namespace App\Models;

class OneOfMyModelsTest extends \CIUnitTestCase
{
public function testFooNotBar()
{
. . .
}
}


You can create any directory structure that fits your testing style/needs. When namespacing the test classes,
remember that the **tests** directory is the root of the ``Tests`` namespace, so any classes you use must
have the correct namespace relative to ``Tests``.
remember that the **app** directory is the root of the ``App`` namespace, so any classes you use must
have the correct namespace relative to ``App``.

.. note:: Namespaces are not required for test classes, but they are helpful to ensure no class names collide.
.. note:: Namespaces are not strictly required for test classes, but they are helpful to ensure no class names collide.

When testing database results, you must use the `CIDatabaseTestClass </testing/database>`_ class.

Expand Down

0 comments on commit 3701b57

Please sign in to comment.