[Gambas-devel] Suggestion : Gambas Unit Testing

Tobias Boege taboege at ...176...
Tue Dec 9 16:09:23 CET 2014


On Tue, 09 Dec 2014, Adrien Prokopowicz wrote:
> 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 ?
> 

I know some people who waited for this. Thank you!

An extra "gbt3" would be the way I prefer, and maybe *somehow* the ability
to specify tests in plain text, i.e. not Gambas code. But that point can
safely be left for the future.

I always imagined the IDE integration to happen in a new .unit directory in
the project directory. This would also enable the archiver to leave unit
tests out when creating a *.gambas file. At least it would be nice if source
and unit tests are somehow separated.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the Devel mailing list