Difference between revisions of "Test-Suite Template"

From ApCoCoAWiki
 
(9 intermediate revisions by 3 users not shown)
Line 3: Line 3:
  
 
==A template for a test-suite==
 
==A template for a test-suite==
Your test should be named like the corresponding package and file ending should be .ts
+
Please respect the following points when writing a test-suite for your package:
 +
*Create a package and name it like the corresponding package, with file ending .ts instead of the usual .cpkg
 +
*Define a function for every test you want to realize.
 +
*Name the functions as follows:
 +
  Test<PackageName><MyTestName>()
 +
*Every function realizes <b>EXACTLY</b> one test.
 +
*A test can <b>FAIL</b> or <b>SUCCEED</b>. The test fails iff the test functions throws an error. To this end, use the AssertXY functions defined in assert.cpkg as much as is sensible. Note, that your test functions do not return anything.
 +
*If you miss some AssertXY function, add it to assert.cpkg.
 +
*You are free to add an arbitrary number of helper functions to your test-suite, just make sure that their names <b>DO NOT</b> start with 'Test'.
  
  -- Test suite for "package name" <br>
+
The following code shows a template for an apcocoa test package. You can find further examples of already existing test-suites in <em>packages/apcocoa/ts</em> of your ApCoCoA directory.
  -------------------------------
+
  Package $apcocoa/ts/template <br>
  -- TEST 01:<br>
+
    Define Initialize()
  Test := Record[Id = "package_01", Descr = "your description"];<br>
+
      -- e.g. initialize variables, that you want to use for all of your tests
  Test.Input :="
+
    EndDefine; <br>
  ''CoCoAL-code to test''
+
    Define TestTemplate01() -- 1st test <br>
  ";<br>
+
      TestRing::=QQ[x,y,z]; <br>
  Test.ExpectedOutput :="
+
      Using TestRing Do
  ''Output of ApCoCoA after executing the code above''
+
        $apcocoa/ts/assert.AssertTrue(x=x, "x does not equal x.");
  ";<br>
+
      EndUsing; <br>
  TSL.RegisterTest(Test);<br>
+
    EndDefine; <br>
  -------------------------------
+
    Define TestTemplate02() -- 2nd test <br>
  -- TEST 02:<br>
+
      TestRing::=ZZ/(2)[x[1..5]]; <br>
  Test := Record[Id = "package_02", Descr = "your description"];<br>
+
      Using TestRing Do
  Test.Input :="
+
        -- implementation of another test
  ''CoCoAL-code to test''
+
      EndUsing; <br>
  ";<br>
+
    EndDefine; <br>
  Test.ExpectedOutput :="
+
    -- TestTemplate03() and so on.. <br>
  ''Output of ApCoCoA after executing the code above''
+
   EndPackage;
  ";<br>
 
  TSL.RegisterTest(Test);
 
   -------------------------------
 
  ...
 
  
==Adding your test-suite to the file apcocoats.cpkg==
+
==Starting your tests==
To add your new test to the complete ApCoCoA-test-suite, you have to add some lines to the file apcocoats.cpkg, This file can be found in the /apcocoa/ts directory.
+
To run all the tests defined in a test-package, call
Insert the name of the testet package into the list "RegisteredTests":
+
  $apcocoa/ts/aunit.RegisterTests("template");
 +
  $apcocoa/ts/aunit.RunTests();
 +
To run just a single test, call TODO.
  
  RegisteredTests := ["glpk",
+
==Assert functions==
    "latte",
+
The following assert functions exist by now.
    "borderbasis",
 
    "linalg",
 
    "linbox",
 
    "iml",
 
    "fglm",
 
    "numabm",
 
    "numbasics",
 
    "numavi",
 
    "yourpackage"];
 
  
==Functions that are useful for testing==
+
*[[AssertTrue]]
For some packages, especially the numerical packages, the testfunction doesn't work very good, because you have to give the exact output-string, which can vary at different computers. For such packages there are some functions, which are listed below:
+
*[[AssertEqualsExact]]
 +
*[[AssertEqualsNumericalNumber]]
 +
*[[AssertEqualsNumericalMatrix]]
 +
*[[AssertEqualsNumericalPoly]]
 +
*[[AssertEqualsListOfNumericalPoly]]

Latest revision as of 18:03, 22 June 2010

Testing an ApCoCoA-Package

This page explains how to create a test-suite for your package. Testing is important to make sure, that your package is still working correctly, when something in ApCoCoA or the ApCoCoALib changes.

A template for a test-suite

Please respect the following points when writing a test-suite for your package:

  • Create a package and name it like the corresponding package, with file ending .ts instead of the usual .cpkg
  • Define a function for every test you want to realize.
  • Name the functions as follows:
 Test<PackageName><MyTestName>()
  • Every function realizes EXACTLY one test.
  • A test can FAIL or SUCCEED. The test fails iff the test functions throws an error. To this end, use the AssertXY functions defined in assert.cpkg as much as is sensible. Note, that your test functions do not return anything.
  • If you miss some AssertXY function, add it to assert.cpkg.
  • You are free to add an arbitrary number of helper functions to your test-suite, just make sure that their names DO NOT start with 'Test'.

The following code shows a template for an apcocoa test package. You can find further examples of already existing test-suites in packages/apcocoa/ts of your ApCoCoA directory.

 Package $apcocoa/ts/template 
Define Initialize() -- e.g. initialize variables, that you want to use for all of your tests EndDefine;
Define TestTemplate01() -- 1st test
TestRing::=QQ[x,y,z];
Using TestRing Do $apcocoa/ts/assert.AssertTrue(x=x, "x does not equal x."); EndUsing;
EndDefine;
Define TestTemplate02() -- 2nd test
TestRing::=ZZ/(2)[x[1..5]];
Using TestRing Do -- implementation of another test EndUsing;
EndDefine;
-- TestTemplate03() and so on..
EndPackage;

Starting your tests

To run all the tests defined in a test-package, call

 $apcocoa/ts/aunit.RegisterTests("template");
 $apcocoa/ts/aunit.RunTests(); 

To run just a single test, call TODO.

Assert functions

The following assert functions exist by now.