B4J Library [B4X] Testing template

With all the talk of templates on the forums, I thought I'd share my test template.

There are many times when I try to decide which is the best method to do something and I find myself regularly rewriting tests.

The main method is:
B4X:
RunTests(CallBack,TestCount, IterationCount , RunDetail , ResultDetail)
'Runtests with detail options
'Callback - The module where the Test1 - Testn methods can be found
'IterationCount - The number of iterations to perform on each test.
'RunDetail - Set to False to hide the status for individual test
'ResultDetail - Set to False to hide the results of each iteration

There are also two helper methods to show all or no detail, just the average test results.

You can create as many test methods as you need in the callback module which should be named Test1 - to Test{n} , just set the TestCount appropriately.

The tests are run in a random sequence for each iteration.

In the test in the Main module I was trying to determine whether to use Regex.Split or substring to parse a line, as you can see if you run fewer iterations and display the full results, there is not much difference although substring wins the day.

The attached project is a B4j project but I have used the XUI library to show a messagebox if you are attempting to run the tests in Debug mode. I think the module should run on all platforms.

For b4a you will need to enable bridge logging in release mode.(#BridgeLogger: True)

I hope you find it useful.

Updated: Added test time to individual test log
 

Attachments

  • TestTemplate.zip
    2.2 KB · Views: 254
  • TestModule.bas
    3 KB · Views: 239
Last edited:

stevel05

Expert
Licensed User
Longtime User
Updated: Added test time to individual test log
 
Top