Changeset 112 for trunk

Show
Ignore:
Timestamp:
02/18/11 14:19:57 (15 months ago)
Author:
mgalloy
Message:

Docs.

Location:
trunk
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/docs/using-mgunit.rst

    r105 r112  
    153153This will send the normal output to the results.log file. 
    154154 
    155 HTML output can also be created with the boolean `HTML`` keyword to the `MGUNIT`` routine. Generally, the `FILENAME` keyword is used in conjunction with this option:: 
     155HTML output can also be created with the boolean `HTML` keyword to the `MGUNIT` routine. Generally, the `FILENAME` keyword is used in conjunction with this option:: 
    156156 
    157157  IDL> mgunit, 'indgen_uts', filename='test-results.html', /html 
  • trunk/overview.txt

    r111 r112  
    1 `mgunit` is a lightweight framework for writing unit tests intended to take the pain out of writing boilerplate code to run tests and tally the results, leaving you free to create as many tests as are useful for your purposes. 
     1`mgunit` is a unit testing framework modeled on other `xUnit testing frameworks <http://en.wikipedia.org/wiki/XUnit>`. The goal is to allow easy creation and reporting of results of tests, while still allowing for many different testing situations. Simple naming conventions replace formal creation of hierarchies and specification of tests. This allows test suites to be created with a minimum of code beyond the actual code of the tests themselves. 
    22 
    3 See ``Using mgunit`` in the `docs` directory for more details about using `mgunit`. 
     3See "Using mgunit" in the `docs` directory for more details about using `mgunit`. 
     4 
     5The basic structure of `mgunit` is that tests are created by subclassing `MGutTestCase`, tests can be grouped together into suites for convenience by subclassing `MGutTestSuite`, and tests are run my calling `mgunit`. The `assert` routine is useful inside a test for making an assertion during the test. The `error_is_pass.pro` batch file is useful to include in a test when the test is supposed to crash.  
    46 
    57:Dirs: 
  • trunk/src/assert.pro

    r104 r112  
    44; Raises an error if the given condition is not met. Uses `logical_predicate` 
    55; to determine truth of condition: so zero or null values are false, anything 
    6 ; else is true. Be careful of conditions like:: 
     6; else is true. Be careful of conditions like the following:: 
    77;      
    88;    assert, not file_test(filename) 
    99; 
    10 ; which use bitwise operators (the above is always false). 
     10; This uses the bitwise `not` operator and therefore this assertation is  
     11; always false. 
     12; 
     13; :Examples: 
     14;    It is typical to check the error in a calculation like the following:: 
     15; 
     16;       assert, error gt tolerance, 'incorrect result, error = %f', error 
     17; 
     18;    It is also useful to check a pre-condition for running a test at the  
     19;    beginning of the test and skip the test if not met:: 
     20; 
     21;       assert, long(strmid(!version.release, 1, 1)) ge 8, $ 
     22;               'IDL version too old: %s', !version.release, $ 
     23;               /skip 
    1124; 
    1225; :Params:  
    1326;    condition : in, required, type=boolean 
    1427;       condition to assert 
    15 ;    msg : in, optional, type=string, default="Assertion failed" 
     28;    msg : in, optional, type=string, default="'Assertion failed'" 
    1629;       message to throw if condition is not met 
    1730;    arg1 : in, optional, type=string 
    18 ;       argument for any C format codes in msg 
     31;       first argument for any C format codes in msg 
    1932;    arg2 : in, optional, type=string 
    20 ;       argument for any C format codes in msg 
     33;       second argument for any C format codes in msg 
    2134;    arg3 : in, optional, type=string 
    22 ;       argument for any C format codes in msg 
     35;       third argument for any C format codes in msg 
    2336; 
    2437; :Keywords: 
    2538;    skip : in, optional, type=boolean 
    26 ;       set to skip test instead of fail 
     39;       set to skip the current test instead of passing or failing 
    2740;- 
    2841pro assert, condition, msg, arg1, arg2, arg3, skip=skip 
  • trunk/src/mgunit.pro

    r109 r112  
    33;+ 
    44; Determines if the current terminal is a TTY, calling `MG_TERMISTTY` safely 
    5 ; even if cmdline_tools is not installed or built. 
     5; even if `cmdline_tools` is not installed or built. 
     6; 
     7; :Private: 
    68; 
    79; :Returns:  
     
    2224 
    2325;+ 
    24 ; Runs unit tests.  
     26; Runs unit tests provided. 
     27; 
     28; :Examples: 
     29;    If there tests `test1_ut__define.pro` and test2_ut__define.pro` had been 
     30;    created, then they could be run like:: 
     31; 
     32;       IDL> mgunit, ['test1_ut', 'test2_ut'] 
     33; 
     34;    Or one could be run individually like:: 
     35; 
     36;       IDL> mgunit, 'test1_ut' 
    2537;  
    2638; :Params: 
    2739;    tests : in, optional, type=strarr 
    28 ;       array of test suites and/or test cases 
     40;       array of test suite and/or test case classnames 
    2941; 
    3042; :Keywords: 
  • trunk/src/mgutclirunner__define.pro

    r104 r112  
    55; runner. The `MGutCliRunner` displays the results in the output log or in a  
    66; log file. 
     7; 
     8; :Private: 
    79;- 
    810 
  • trunk/src/mgutcompoundrunner__define.pro

    r104 r112  
    55; runner. The `MGutCompoundRunner` allows results to be sent to multiple 
    66; test runners, e.g., to the display and to a file. 
     7; 
     8; :Private: 
    79;- 
    810 
  • trunk/src/mgutguirunner__define.pro

    r107 r112  
    44; Results for tests, test cases, and test suites are reported to the test  
    55; runner. The `MGutGUIRunner` displays the results in an interactive GUI. 
     6; 
     7; :Private: 
    68;- 
    79 
  • trunk/src/mguthtmlrunner__define.pro

    r104 r112  
    44; Results for tests, test cases, and test suites are reported to the test  
    55; runner. The `MGutHTMLRunner` displays the results in the output HTML file. 
     6; 
     7; :Private: 
    68;- 
    79 
  • trunk/src/mgutjunitrunner__define.pro

    r107 r112  
    2626;      </testsuite> 
    2727;    </testsuites> 
     28; 
     29; :Private: 
    2830;- 
    2931 
  • trunk/src/mguttestcase__define.pro

    r107 r112  
    22 
    33;+ 
    4 ; Subclass `MGutTestCase` to actually write tests. Any function method whose  
    5 ; name starts with "test" will be considered a test. Tests are executed and  
    6 ; results are reported to the test runner object. 
    7 ;- 
     4; Subclass `MGutTestCase` to actually write tests. In a subclass of  
     5; `MGutTestCase`, any function method whose name starts with "test" will be  
     6; considered a test. Tests are executed and results are reported to the test  
     7; runner object. 
     8; 
     9; :Examples: 
     10;    To write your own tests, simply subclass from this class and make methods 
     11;    that start with "test":: 
     12; 
     13;       pro mytest::test_myroutine 
     14;         compile_opt strictarr 
     15;           
     16;         answer = myroutine(1.0)   ; answer should be 2. 
     17;         assert, abs(answer - 2.) lt 0.01, 'incorrect result, %f', answer 
     18; 
     19;         return, 1 
     20;       end 
     21; 
     22;       pro mytest__define 
     23;         compile_opt strictarr 
     24;           
     25;         define = { mytest, inherits MGutTaseCase } 
     26;       end 
     27; 
     28; :Properties: 
     29;    npass : type=integer 
     30;       number of passing tests 
     31;    nfail : type=integer  
     32;       number of failing tests 
     33;    nskip : type=integer  
     34;       number of skipped tests 
     35;    ntests : type=integer 
     36;       number of tests 
     37;    testnames : type=strarr  
     38;       array of method names which begin with "test" 
     39;- 
     40 
    841 
    942;+ 
     
    2760;+ 
    2861; Set this test to be skipped. 
     62; 
     63; :Private: 
    2964;- 
    3065pro mguttestcase::skip 
     
    3873; This is a safe place to actually run a single test. Any errors that occur  
    3974; are assumed to be from the test and recorded as a failure for it. 
     75; 
     76; :Private: 
    4077; 
    4178; :Returns:  
     
    75112; Run setup method before each test. 
    76113; 
     114; :Private: 
     115;  
    77116; :Keywords: 
    78117;    fail : out, optional, type=boolean 
     
    98137; Run teardown method before each test. 
    99138; 
     139; :Private: 
     140; 
    100141; :Keywords: 
    101142;    fail : out, optional, type=boolean 
     
    119160 
    120161;+ 
    121 ; Removes the given prefix from the msg if present. 
     162; Removes the given `prefix` from the `msg` if present. 
    122163;  
     164; :Private: 
     165; 
    123166; :Params: 
    124167;    msg : in, required, type=string 
     
    139182;+ 
    140183; Display test results via test runner methods. 
     184; 
     185; :Private: 
    141186;- 
    142187pro mguttestcase::display 
     
    167212; Run the tests for this class (i.e. methods with names that start with  
    168213; "test"). 
     214; 
     215; :Private: 
    169216;- 
    170217pro mguttestcase::run 
     
    258305; Find the name and number of tests (i.e. methods with names that start with  
    259306; "test"). 
     307; 
     308; :Private: 
    260309;- 
    261310pro mguttestcase::findTestnames 
     
    284333;+ 
    285334; Get properties of the object. 
    286 ;  
    287 ; :Keywords: 
    288 ;    npass : out, optional, type=integer 
    289 ;       number of passing tests 
    290 ;    nfail : out, optional, type=integer  
    291 ;       number of failing tests 
    292 ;    nskip : out, optional, type=integer  
    293 ;       number of skipped tests 
    294 ;    ntests : out, optional, type=integer 
    295 ;       number of tests 
    296 ;    testnames : out, optional, type=strarr  
    297 ;       array of method names which begin with "test" 
    298335;- 
    299336pro mguttestcase::getProperty, npass=npass, nfail=nfail, nskip=nskip, $ 
     
    312349; Test suites can contain other test suites or test cases. The level is the 
    313350; number of layers down from the top most test suite (level 0). 
     351; 
     352; :Private: 
    314353; 
    315354; :Params: 
  • trunk/src/mguttestrunner__define.pro

    r91 r112  
    55; runner. Each subclass of MGutTestRunner displays them in some way.  
    66; MGutTestRunner itself is abstract and shouldn't be instantiated.   
     7; 
     8; :Private: 
    79;- 
    810 
  • trunk/src/mguttestsuite__define.pro

    r107 r112  
    55; and add test suites/test cases in its `init` method or create an  
    66; `MGutTestSuite` and use the `add` method to add test suites/cases. 
     7; 
     8; For example, it is typical do create a test suite like the following:: 
     9; 
     10;    function mytestsuite_uts::init, _extra=e 
     11;      compile_opt strictarr 
     12; 
     13;      if (~self->MGutTestSuite::init(_strict_extra=e)) then return, 0 
     14; 
     15;      self->add, /all 
     16; 
     17;      return, 1 
     18;    end 
     19; 
     20;    pro mytestsuite_uts__define 
     21;      compile_opt strictarr 
     22; 
     23;      define = { MyTestSuite_uts, inherits MGutTestSuite } 
     24;    end 
     25; 
     26; This test will add all the files in the current directory that end in  
     27; "_ut__define.pro" as test cases. Then the following will run all the test 
     28; cases in a directory:: 
     29; 
     30;    IDL> mgunit, 'mytestsuite_uts' 
     31; 
     32; :Properties: 
     33;    home : type=string 
     34;       location of the root of the test suite 
     35;    failures_only : type=boolean 
     36;       set to report only failed tests 
     37;    name : type=string 
     38;       name of the object 
     39;    npass : type=integer 
     40;       number of passing tests contained in the hierarchy below this object 
     41;    nfail : type=integer 
     42;       number of failing tests contained in the hierarchy below this object 
     43;    nskip : type=integer 
     44;       number of skipped tests contained in the hierarchy below this object 
     45;    ntestcases : type=integer 
     46;       number of directly contained test suites or test cases 
     47;    ntests : type=integer 
     48;       number of tests contained in the hierarchy below this object 
     49;    test_runner : in, required, type=object 
     50;       subclass of `MGtestRunner` 
    751;- 
    852 
     
    1155; Recompile the class definition before creating the object to make sure it is 
    1256; the newest definition (convenient when making changes to a test). 
     57; 
     58; :Private: 
    1359; 
    1460; :Params: 
     
    3480; it. 
    3581; 
     82; :Private: 
     83; 
    3684; :Returns:  
    37 ;    obj 
     85;    object 
    3886; 
    3987; :Params: 
     
    67115; Recompiles all test cases contained by the suite or contained by child  
    68116; suites. 
     117;  
     118; :Private: 
    69119;- 
    70120pro mguttestsuite::recompileTestCases 
     
    84134;+ 
    85135; Display test results via test runner methods. 
     136;  
     137; :Private: 
    86138;- 
    87139pro mguttestsuite::display 
     
    110162;+ 
    111163; Run the contained test suites or test cases. 
     164; 
     165; :Private: 
    112166;- 
    113167pro mguttestsuite::run 
     
    158212;       set to add all the files in the current directory that end in  
    159213;       "_ut__define.pro" (the current directory is defined to be the  
    160 ;       directory where the method calls this method is located) 
     214;       directory where the method calling this method is located) 
    161215;- 
    162216pro mguttestsuite::add, tests, all=all 
     
    232286;+ 
    233287; Get properties of the object. 
    234 ; 
    235 ; :Keywords: 
    236 ;    name : out, optional, type=string 
    237 ;       name of the object 
    238 ;    npass : out, optional, type=integer 
    239 ;       number of passing tests contained in the hierarchy below this object 
    240 ;    nfail : out, optional, type=integer 
    241 ;       number of failing tests contained in the hierarchy below this object 
    242 ;    nskip : out, optional, type=integer 
    243 ;       number of skipped tests contained in the hierarchy below this object 
    244 ;    ntestcases : out, optional, type=integer 
    245 ;       number of directly contained test suites or test cases 
    246 ;    ntests : out, optional, type=integer 
    247 ;       number of tests contained in the hierarchy below this object 
    248288;- 
    249289pro mguttestsuite::getProperty, name=name, $ 
     
    275315; number of layers down from the top most test suite (level 0). 
    276316; 
     317; :Private: 
     318; 
    277319; :Params: 
    278320;    level : in, required, type=integer 
     
    311353;    home : in, optional, type=string, default='' 
    312354;       location of the root of the test suite 
    313 ;    test_runner : in, required, type=object 
    314 ;       subclass of MGtestRunner 
    315 ;    failures_only : in, optional, type=boolean 
    316 ;       set to report only failed tests 
     355 
     356 
    317357;- 
    318358function mguttestsuite::init, name=name, home=home, test_runner=testRunner, $ 
  • trunk/src/mgutxmlrunner__define.pro

    r108 r112  
    44; Results for tests, test cases, and test suites are reported to the test  
    55; runner. The `MGutXMLRunner` displays the results in the output XML file. 
     6; 
     7; :Private: 
    68;- 
    79