Download the PHP package joefallon/kisstest without Composer
On this page you can find all versions of the php package joefallon/kisstest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joefallon/kisstest
More information about joefallon/kisstest
Files in joefallon/kisstest
Package kisstest
Short Description KissTest is command-line free, fast, simple and beautiful unit test framework.
License MIT
Homepage https://github.com/joefallon/kisstest
Informations about the package kisstest
KissTest
By Joe Fallon
A Keep-It-Simple-Straightforward, fast, and beautiful xUnit style unit test library.
Here is an example of some passing tests:
It provides several useful features and benefits not available in other unit testing frameworks:
- The display of the testing results is completely displayed right in the browser. The layout is beautiful and non-saturated colors were chosen giving a wonderful testing experience.
- Detailed metrics for all tests is displayed right in the browser window. Now you can immediately determine which tests are taking so much time.
- The results of all the tests are displayed in a table of contents format. If a test failed, it will be red. Click on it and go right to the results for the failing test. Then, click the handy "top" link and go right back to the table of contents. Better yet, fix the test, press F5 and see the test go green.
- No CLI access is needed. None.
- Technically, the CLI PHP executable is not the same one that is used to serve web pages. It's close, but not the same one. Since the CLI is not used in KissTest, the execution environment can be set up to be identical to the production environment. Having the production environment match the testing environment as close as practical is always a great practice.
- It's fast. Really fast. No code injection, dynamic class modification, or eval is used anywhere. The testing framework is light and nimble.
- Easy to understand. Do you have a new developer on your team that is a little green and inexperienced? No problem, this testing framework can be learned in 10-15 minutes.
- A full mocking and class stubbing solution is included as well.
- The mocking/stubbing functionality is simple and fast. Really fast.
- All test suite setup is performed via plain PHP. No annotations. No XML. No JSON. No *.ini files. Just simple, sweet, and to-the-point PHP.
Here is an example containing some failing tests with some useful features annotated:
Installation
The easiest way to install KissTest is with
Composer. Create the following composer.json
file
and run the php composer.phar install
command to install it.
Configuration and Test Setup
Directory Structure
Since KissTest uses just PHP for configuration there are an infinite number of ways to configure and set up a test suite. The following method is simple and straight forward.
Here is an example directory structure structure:
Here is the directory for KissTest:
Here we see where the source (a.k.a. "src") directory and "tests" directory and additional (optional) configuration file is created:
Here we see that the directory structure of the source code subtree and the unit test code subtree mirrors each other:
Here we see the index.php
file that defines the tests included in the test
suite, a unit test file and the associated production code file:
Test Suite Specification (tests/index.php)
The test specification exists within the index.php
file. Here is an example:
Additional Configuration (tests/config/main.php)
The configuration file (tests/config/main.php
) is where the following
is placed:
- Autoloading configuration
- Database cleaning
- Defining global constants (if any)
Here is an example configuration file:
Class Documentation
Only two classes are needed for all unit testing needs. The first is
UnitTest
and the second is Mock
. UnitTest
is a class that
all unit testing classes inherit from and that also contains all of
the test cases. Mock
is a class that is used for all stubbing
and all mocking. No other classes from the unit testing framework are
needed.
UnitTest
When using the class UnitTest
, a few rules need to be followed:
- Your unit test class must inherit from class
UnitTest
. - The names of all unit test methods (i.e. test cases) must begin
with the string
test_
. - A test is considered to have passed if it does not fail an assert,
or
notImplementedFail()
is not called, ortestFail()
was not called. - When the name of the test case is displayed, all underscores are changed to spaces. Therefore, your test case method names can read just like sentences when they are viewed in the browser.
Example Unit Test Class
Here is an example unit test class:
Assertion Methods in UnitTest
The following assertion methods are available in the base class UnitTest:
Test Not Implemented
Sometimes, a test method is created but the test method body has not been
completed. In this case the method notImplementedFail()
should be used.
Here is an example of using notImplementedFail()
:
Test Setup and Teardown
Sometimes a certain set of tasks will need to be performed every time a test is
ran and another set of tasks will need to be performed every time a test completes.
For example, perhaps an object graph needs to be created and then torn down
and it is used in every test. The empty methods (i.e. hooks) setUp()
and
tearDown()
are exactly for this purpose.
Here is an example of the test case setup and tear down:
Testing for Exceptions
Testing for exceptions is very easy. Here is an example of testing for an exception:
Mock
Mock
is an extremely simple to understand and extremely fast stubbing and
mocking solution. All types of mocking and stubbing needs can be satisfied via
its use.
The use of Mock requires the cooperation of three different classes:
- The class under test.
- The unit test class that contains the methods for testing the class under test.
- The mock/stub (the same class satisfies both needs) class for the class under test.
Here is an example class under test:
Here is the class that will be mocked out:
Here is the class DependencyClass
fully mocked/stubbed out:
Finally, here is the unit test that ties it all together:
The mocks can be used as stubs by simply not asserting on any of the methods in
the instance of Mock
held by the mock.stub class. Since no reflection, eval,
or injection is used, the mock/stub classes are extremely fast.