SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Thread Tools Display Modes
Old 18/04/2015, 10:38 AM   #1
corne's Avatar
Join Date: Jul 2010
Location: The Netherlands
Posts: 686
Reputation: 195
Default y_testing - Simple framework for writing unit tests.


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


This library is a part of YSI, which can be found here. Keep your eye on that topic and your server log for updates.

YSI Download Topic


To use add:

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

    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):

    // Initialise data to be used in a test.

    // 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:

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.


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

        b = random(10);
    ASSERT(0 <= b < 10);
    return true;

I am reposting this include (made by Y_Less) with the thought of what he said to several members of the community. Everything that could help someone should not be deleted from the forums, which is something I agree with since I learned a lot by reading the tutorials on here. He made a lot of things that are used by lots of servers and that knowledge should not be lost for present and future developers.
corne is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] y_testing Misiur Tutorials 0 16/04/2015 06:38 PM
[Include] ut_mock_players - y_testing mock player generator Misiur Includes 7 03/02/2014 03:46 AM
Problem writing a simple login/register thing knackworst Scripting Help 11 31/08/2013 12:58 PM
Fun tests to take. Mrkrabz Everything and Nothing 5 06/08/2010 12:58 PM

All times are GMT. The time now is 02:27 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.