A Gambas component for unittesting and test-driven programming. With this component you can develop software in a test-driven matter (write test first, program functionality afterwards) and you are able to ensure that on refactoring the desired results of your code stays the same.
Tests are output as [Tap](https://testanything.org/) so that they can be displayed, analyzed or viewed with any [Tap consumer](https://testanything.org/consumers.html). As each output containes a summary at the end with the string "PASSED" or "FAILED" at the last line you can even view the console output to decide whether the test has been successful or not.
Start by creating a Testmodule, this is a class with any name, but the ending ".test", for example "TestHelloWorld.test". This class contains one or more public Subs, from which each represent a so called Testmethod.
If you did all this correctly and now hit <F5>, Gambas will execute the startfunction in module TestMe, which runs through the Testmethods of our Testmodule and presents the test result in the console, for example (this is from unittesthelloworld):
If a failure occurs it will report FAILED instead of PASSED and will show you the place of the failure. I you want to debug the code you can set a breakpoint inside TestHello.TestRight, hit <F5> again and start debugging.
Testmodule and Testmethods can be named the same way as any Gambas Module or Method except that a Testmethod may not be named _Setup(), _Teardown(), _SetupEach() or _TeardownEach().
You also can test your on the console. The command **/usr/bin/gbt3 /path/to/my/project** executes the unittests and prints the result to standard output:
Sometimes it is neccessary to create a "fixture", a special environment for a test or a couple of tests, and to destroy this environment after the test is done. For example a database connection should be established at the beginning of all tests, some tables for testing should be created and deleted for every single testmethod and the database connection should be closed at the end. This can be done with Setup... and Teardown... functions inside the Testmodule.
You can create methods with these names to create an environment for each testmethod before it is invoked and to destroy it afterwards. If you have five testmethods inside your testmodule these functions will be invoked five times, _SetupEach() before each testmethod, _TeardownEach() after each testmethod. Got it?
You can create methods with these names to create an environment for all testmethods inside a testmodule, in the beginning _Setup() is invoked and after all testmethods inside the testmodule are done you can destroy the environment with _Teardown().