[Gambas-user] Integrate unittest component to Gambas

Benoît Minisini g4mba5 at gmail.com
Sat Apr 21 22:56:48 CEST 2018


Le 21/04/2018 à 22:04, Christof Thalhofer a écrit :
> Am 21.04.2018 um 19:43 schrieb Benoît Minisini:
> 
>> No problem to add a new component, but I'm not sure to understand your
>> interface. So maybe I will tell rubbish.
> 
> Maybe I will tell rubbish too. I forked this project from
> http://comunit.sourceforge.net/
> 
> So I did not develop the interface but I rearranged it to work in
> Gambas. I fixed a couple of selfmade bugs and ran it for a while in my
> projects. Like so:
> 
> Just try it out with <F5>
> 
> In TesteStartRunner the unittest tests itself in two ways:
> 
> r.Test(...)
> delivers the testresult(s) to the console.
> 
> (This is the way I work very often. I first write a test, and then do my
> coding. If I hit <F5> the Unittest runs and shows the results in the
> console. If everything is ok, my new method is ok ...)
> 
> Be aware that the tests which test gb.deg.unittest itself intentionally
> are not successful.
> 
> r.ShowTestForm()
> delivers the GUI
> 
> (which is nice but I use it not very often, it is nice for playing
> around, but quite annoying when constantly coding on new things)
> 
>> ATestContainer -> it's actually the parent class for all tests?
> 
> Yes ... and no ... it is the parent class for all test *containers*. A
> container can contain a lot of tests. All test containers in a project
> (this is the "Test Suite") are identified by being inherited from
> ATestContainer.
> 
> I know, "ATestContainer" is not a nice name ...
> 
>> UnitTest -> Why this class? And why do you have to instanciate it? If it
>> is just there to run all the test, I suggest mergin UnitTest and
>> ATestContainer, and just make a static method "Run()" to run all the
>> unit tests in the exported classes inheriting the new "UnitTest".
> 
> UnitTest identifies all testcontainers within a project, collects them
> and runs all tests in all containers, or all tests in a single
> container, or even just single test and then collects and displays the
> results.
> 
> Merging ATestContainer and UnitTest could be much more elegant, yes.
> I will try it out.
> 
> For now I was not able to make UnitTest.Test (the equivalent of "run")
> static.

Why having several tests in the same class? I think if you do that, it 
means that you always want to run all of them, don't you?

In ohter words, all tests located in a Test container should be run from 
one Run() method.

> 
>> As for the GUI, I think it should be be extern to the tested project and
>> merged into the IDE.
> 
> Yes. But I think it is important to be able to run the unittest inside
> the project itself, even afterwards, when it is compiled, and not only
> through the IDE. There I think of automatic testing of all kind of
> libraries, components or programs.
> 
>> The result of the tests should be provided to the standard output in a
>> standard format that will be displayed by your GUI in the IDE.
> 
> Do you know a standard format for unittesting results? Something like
> this? https://testanything.org/
> 
> This is for displaying only.
> 
> You mean sth like JSON? Ok, there would have to be coded methods like:
> 
> TestResult.ToJson
> and
> TestResult.FromJson
> 
> to ex- and import Testresults.

Not necessarily. I just mean that running the test from the command line:

$ gbr3 -s UnitTest myproject.gambas

will run the static UnitTest.Main() method, that should run all the unit 
tests located in the project, and print the result to the standard output.

This result does not have to use a standard format, just a format that 
is easy to parse to implement the GUI in the IDE.

But if you know a standard format for unit test results, you can use it 
of course.

As for exporting the unittest classes, this is not necessary.

As soon as you are inside a project, you can browse the ".gambas" 
directory to get the name of each class of the project (in uppercase) 
and the Class.Stat() method of the gb.util component to get information 
about a class (its name and its parent class).

I could even add a method in the gb.util component to return the list of 
all classes.

And to go further, there is still a problem: a normal project having 
unit tests will always load the gb.unittest component even when running 
no test. There is no way to prevent that at the moment, but if you 
succeed in merging the ATestContainer and UnitTest, and separating the 
GUI from the component, I will see what I can do.

Regards,

-- 
Benoît Minisini


More information about the User mailing list