[Gambas-devel] Suggestion : Gambas Unit Testing

Adrien Prokopowicz adrien.prokopowicz at ...176...
Tue Dec 9 01:57:43 CET 2014


Hello everyone !

With the amount of features to test in my various Gambas projects, I  
started feeling that it was a pain to write the tests, run *all* of them,  
and analyzing their output each time I had to make a change, thus leading  
to forget to run simple tests (see the last gb.xml issue...).

Therefore, in order to automate and simplify this whole process, I decided  
to start working on an Unit Testing component for Gambas.

It works quite simply : in your project, just create a class that inherits  
the UnitTest class, move it inside an "unit" folder in your project source  
directory, and implement your test in the _Run() method, using the  
different Assert() and Fail() methods, documented in the component's  
'AssertionsTests' test.

To run all the tests at once, just use the _UnitTestLauncher module as the  
starting class instead of your project's default one (this can be achieved  
easily using 'gbx3 -s _UnitTestLauncher' inside your project's directory.
Each test is run inside a separate Task, therefore preventing a bad test  
to crash the whole test suite, and allowing you to easily multi-task it,  
using 'gbx3 -s _UnitTestLauncher -- -j <number of parallel tasks>'.

Inside the attached component, I also made 3 tests, that show how the  
component handles the different scenarios :

- The 'MyGoodUnitTest' will run fine, but will sleep 0.5s before ending  
(to show that the component will use another thread to run the other  
tests, if there is any available, which is not the case by default).
- The 'MyBadUnitTest' will fail because of an (obvious) false assert. It  
will then show the stack trace of where the error raised, as well as a  
reason text (or just 'Assertion failed.' by default).
- The 'MyVeryBadUnitTest' will fail because of an error raised by the  
interpreter, here 'Division by zero'. Note that the result will be similar  
if the test completely crashes (Segfault...), you just won't have a stack  
trace available.

Of course this is just a proof of concept, there are a few things i would  
like to add to properly finish this component, such as a proper IDE  
integration, a standardized xUnit XML output, tweaking the archiver so the  
tests won't be in the final executable, maybe its own command (like gbt3)  
...

What do you think ?

-- 
Adrien Prokopowicz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gb.unit-0.0.1.tar.gz
Type: application/x-gzip
Size: 8133 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/devel/attachments/20141209/bdcc22ea/attachment.bin>


More information about the Devel mailing list