[Tutorial] y_testing
#1

Introduction

This library allows you to write tests JUnit style - as in the name determines that they're tests.

Download

This library is a part of YSI.

http://github.com/Misiur/YSI-Includes

Use

To use add:

Code:
#define RUN_TESTS
#include <YSI\y_testing>
You can then write tests as:

Code:
Test:Something()
{
    return true;
}
Each function declared as "Test:" will be run when "Testing_Run" is called. If a test returns true it succeeded, if it returns false it failed.

In the spirit of JUnit you can also do (useful for setting up and destroying databases etc):

Code:
TestInit:Something()
{
    // Initialise data to be used in a test.
}

TestClose:Something()
{
    // Close something used in a test.
}
If you have a "TestInit:" or "TestClose:" function with the same name as a "Test:" function they will be called before and after the main test.

To run tests call:

Code:
new
    tests,
    fails,
    func[33];
Testing_Run(tests, fails, func);
The first parameter returns the number of tests run. The second parameter returns the number of tests that failed. The third parameter returns the name of the first function that failed. The function itself returns true if no tests failed. Note that the third parameter is optional.

The "RUN_TESTS" define means that tests are included - if you comment out this line all tests will be removed from the script.

ASSERT

You can call "ASSERT" inside a test to check some condition is true:

Code:
Test:Something()
{
    new
        b = random(10);
    ASSERT(0 <= b < 10);
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)