Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: improve app testing writeup #1936

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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