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 Testcontainer, 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 Testcase.
If you did all this correctly and now hit <F5>, Gambas will execute the startfunction in module TestMe, which runs through the Testcases of our Testcontainer 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.
Testcontainer and Testcases can be named the same way as any Gambas Module or Method except that a Testcase 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 testcase and the database connection should be closed at the end. This can be done with Setup... and Teardown... functions inside the Testcontainer.
You can create methods with these names to create an environment for each Testcase before it is invoked and to destroy it afterwards. If you have five Testcases inside your Testcontainer these functions will be invoked five times, SetupEach() before each Testcase, TeardownEach() after each Testcase. Got it?
You can create methods with these names to create an environment for all Testcases inside a Testcontainer, in the beginning Setup() is invoked and after all Testcases inside the Testcontainer are done you can destroy the environment with Teardown().