Below is an example of a simple test suite that you can create to test your functions and make sure they return the correct results.
cm.test package is needed for the test functions to work properly.
/** * TestSuite */ public void testSuite() { testSuiteLog.begin(); testSuiteLog.verbose = true; testSuiteLog.next("test arithmetic"); test 1 + 1 => 2; test testCase1() => 2; test testCase2() => 3; testSuiteLog.next("test boolean"); test testBool1() => true; test testBool2() => false; testSuiteLog.dump(); testSuiteLog.end(); } /** * Test case 1 */ public int testCase1() { return 1 + 1; } /** * Test case 2 */ public int testCase2() { return 1 + 2; } /** * Test bool 1 */ public bool testBool1() { return true; } /** * Test bool 2 */ public bool testBool2() { return false; }
Running the testSuite()
method above will net you this result in your emacs console:
Instead of initializing the testSuiteLog
yourself as shown in testSuite()
, there is also a predefined syntax that you can use.
//run this with C-M-p minitest() { testSuiteLog.next("test arithmetic"); test 1 + 1 => 2; test testCase1() => 2; test testCase2() => 3; testSuiteLog.next("test boolean"); test testBool1() => true; test testBool2() => false; }
Example of Test Suite for Reconfig
reconfigs/test/suite.cm: public void reconfigsTestSuite() { pln("Running Reconfigs test suite"); testSuiteLog.begin(); reconfigsSimpleTest(); reconfigsComplexCompareTest(); reconfigsTwoLevelCompareTest(); testSuiteLog.dump(label="Reconfigs test suite results:"); testSuiteLog.end(); } ... { reconfigsTestSuite(); }
Register your test suite/s with registerExternalSuite()
. See the example below:
public void start(ExtensionEnv env) { //Init reconfigs test suite: registerExternalSuite("custom.reconfigs.test", "suite1.cm"); registerExternalSuite("custom.reconfigs.test", "suite2.cm"); super(env); }
If you want to register several test suite files from the same package, you can also use this function:
registerExternalSuites(str package, str[] files)
The test suite should be registered in the start()
method in the extension.cm file corresponding to your own test extension
Then, you will be able to run the test suite from the test suite dialog. All test suites corresponding to your installed test extensions will be shown in this dialog. You can open the test suite dialog from the Auto Crash dialog or from the Release debug dialog.
Open the auto crash dialog by pressing F12 or open the Release debug dialog by pressing Ctrl-Alt-F12
Press the Test Suite button
Comments
0 comments
Please sign in to leave a comment.