29.11.2015, 19:31
pawn-test
pawn-test is a simple automated testing framework for PAWN code. The framework provides a number of functions for setting up and managing test suites and test cases. It was designed to be compatible with the PAWN compiler that comes with San Andreas: Multiplayer (Pawn 3.2.3664), but with a bit of tinkering it should work with other PAWN projects as well.
Even though there exists a working testing environment for SA:MP (that would be y_testing), it is part of the YSI library, which many scripters do not want to deal with. It also creates a lot of syntactic sugar which may not appeal to everyone. This is a standalone, lightweight library that can be used without additional dependencies.
License
pawn-test is an open source project covered by the MIT License. See the attached LICENSE file for more information or visit http://opensource.org/licenses/MIT.
Using pawn-test
To use pawn-test in a PAWN project, copy the src directory into your project's pawno/include directory. Rename the directory to pawn-test.
To run pawn-test with the default configuration, simply include the bootstrapper in your project:
If you want to provide your own configuration, edit the configuration file (config.inc) and change your settings there.
Getting Started
The pawn-test documentation includes an article on how to get started, but a unit test for a simple test function looks something like this:
This produces the following output:
Download
pawn-test is developed on GitHub. The latest stable release can be downloaded as a zip/tarball from the downloads page.
The complete documentation is available in the wiki of the repository. Every API function is documented and the API documentation can be generated using pawncc and a file in the /docs directory.
pawn-test is a simple automated testing framework for PAWN code. The framework provides a number of functions for setting up and managing test suites and test cases. It was designed to be compatible with the PAWN compiler that comes with San Andreas: Multiplayer (Pawn 3.2.3664), but with a bit of tinkering it should work with other PAWN projects as well.
Even though there exists a working testing environment for SA:MP (that would be y_testing), it is part of the YSI library, which many scripters do not want to deal with. It also creates a lot of syntactic sugar which may not appeal to everyone. This is a standalone, lightweight library that can be used without additional dependencies.
License
pawn-test is an open source project covered by the MIT License. See the attached LICENSE file for more information or visit http://opensource.org/licenses/MIT.
Using pawn-test
To use pawn-test in a PAWN project, copy the src directory into your project's pawno/include directory. Rename the directory to pawn-test.
To run pawn-test with the default configuration, simply include the bootstrapper in your project:
Код:
#include <pawn_test/pawn_test>
Getting Started
The pawn-test documentation includes an article on how to get started, but a unit test for a simple test function looks something like this:
pawn Код:
#include <a_samp>
#include <pawn_test/pawn_test>
forward CheckAnswer();
stock AddOne(x)
{
return x + 1;
}
public CheckAnswer()
{
return PawnTest_Assert( AddOne(5) == 7, "AddOne(5) == 7" );
}
main()
{
new TestSuite = PawnTest_InitSuite("My First Unit Test");
PawnTest_AddCase(TestSuite, "CheckAnswer");
PawnTest_Run(TestSuite);
PawnTest_DestroySuite(TestSuite);
}
Код:
[==========] running test suite "My First Unit Test" w/ 1 test case(s)... [ RUN ] test "CheckAnswer" (100%) assertion "AddOne(5) == 7" failed. [ FAIL ] test "CheckAnswer" (1 ms, 0.001 s in total). [==========] test suite "My First Unit Test" (#0) finished, 1 test(s) ran. [ FAILED ] 1/1 test(s) failed. [==========] testing stopped.
pawn-test is developed on GitHub. The latest stable release can be downloaded as a zip/tarball from the downloads page.
The complete documentation is available in the wiki of the repository. Every API function is documented and the API documentation can be generated using pawncc and a file in the /docs directory.