[Gambas-user] Using test interface for scripter testing
taboege at gmail.com
Mon Jun 22 22:44:39 CEST 2020
On Mon, 22 Jun 2020, Brian G wrote:
> I have a few question regarding, how to test for output from an application, IE the printed output
> for example if my command line is gbs3 -v and it print 3.14.5
> how do I capture the output and compare in the test class
> I see how to test functions and class function within an application.
> can i do an exec and capture output in the test module then compare?
There is no dedicated assertion for running an external program and
comparing its output. You would have to do it in steps:
Dim sOut As String
Exec ["gbs3", "-v"] To sOut
Test.Equals(sOut, "3.14.5", "scripter version is 3.14.5")
> can i compare the content of an output file with an expected output using fileload... within the test module
> What is allowed?
A test module is mostly a normal Gambas module. The only difference
is that the execution of its methods is orchestrated and wrapped by
gb.test. You can do everything you would normally do in Gambas --
although for somewhat technical reasons you should avoid anything
that prints to stdout. (If you must, use Test.Note).
The test methods (subroutines in your test module) run any kind of
Gambas code and occasionally call methods of the Test class to make
assertions about the current state of the process. The test results
you communicate via assertions are redirected to a side channel
(actually, the main channel, stdout, which is why you should not
print to it by yourself).
Of course you can File.Load and Exec. You can even set up databases,
download files from the web or show a GUI form in your test methods.
It's normal startup class-style code that makes use of the Test class
to report test results. The parts of Gambas you can use is not
restricted by gb.test.
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User