- Timestamp:
- 02/18/11 14:19:57 (15 months ago)
- Location:
- trunk
- Files:
-
- 13 modified
-
docs/using-mgunit.rst (modified) (1 diff)
-
overview.txt (modified) (1 diff)
-
src/assert.pro (modified) (1 diff)
-
src/mgunit.pro (modified) (2 diffs)
-
src/mgutclirunner__define.pro (modified) (1 diff)
-
src/mgutcompoundrunner__define.pro (modified) (1 diff)
-
src/mgutguirunner__define.pro (modified) (1 diff)
-
src/mguthtmlrunner__define.pro (modified) (1 diff)
-
src/mgutjunitrunner__define.pro (modified) (1 diff)
-
src/mguttestcase__define.pro (modified) (11 diffs)
-
src/mguttestrunner__define.pro (modified) (1 diff)
-
src/mguttestsuite__define.pro (modified) (10 diffs)
-
src/mgutxmlrunner__define.pro (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/using-mgunit.rst
r105 r112 153 153 This will send the normal output to the results.log file. 154 154 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::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:: 156 156 157 157 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. 2 2 3 See ``Using mgunit`` in the `docs` directory for more details about using `mgunit`. 3 See "Using mgunit" in the `docs` directory for more details about using `mgunit`. 4 5 The 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. 4 6 5 7 :Dirs: -
trunk/src/assert.pro
r104 r112 4 4 ; Raises an error if the given condition is not met. Uses `logical_predicate` 5 5 ; 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:: 7 7 ; 8 8 ; assert, not file_test(filename) 9 9 ; 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 11 24 ; 12 25 ; :Params: 13 26 ; condition : in, required, type=boolean 14 27 ; condition to assert 15 ; msg : in, optional, type=string, default=" Assertion failed"28 ; msg : in, optional, type=string, default="'Assertion failed'" 16 29 ; message to throw if condition is not met 17 30 ; arg1 : in, optional, type=string 18 ; argument for any C format codes in msg31 ; first argument for any C format codes in msg 19 32 ; arg2 : in, optional, type=string 20 ; argument for any C format codes in msg33 ; second argument for any C format codes in msg 21 34 ; arg3 : in, optional, type=string 22 ; argument for any C format codes in msg35 ; third argument for any C format codes in msg 23 36 ; 24 37 ; :Keywords: 25 38 ; skip : in, optional, type=boolean 26 ; set to skip t est instead of fail39 ; set to skip the current test instead of passing or failing 27 40 ;- 28 41 pro assert, condition, msg, arg1, arg2, arg3, skip=skip -
trunk/src/mgunit.pro
r109 r112 3 3 ;+ 4 4 ; 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: 6 8 ; 7 9 ; :Returns: … … 22 24 23 25 ;+ 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' 25 37 ; 26 38 ; :Params: 27 39 ; tests : in, optional, type=strarr 28 ; array of test suite s and/or test cases40 ; array of test suite and/or test case classnames 29 41 ; 30 42 ; :Keywords: -
trunk/src/mgutclirunner__define.pro
r104 r112 5 5 ; runner. The `MGutCliRunner` displays the results in the output log or in a 6 6 ; log file. 7 ; 8 ; :Private: 7 9 ;- 8 10 -
trunk/src/mgutcompoundrunner__define.pro
r104 r112 5 5 ; runner. The `MGutCompoundRunner` allows results to be sent to multiple 6 6 ; test runners, e.g., to the display and to a file. 7 ; 8 ; :Private: 7 9 ;- 8 10 -
trunk/src/mgutguirunner__define.pro
r107 r112 4 4 ; Results for tests, test cases, and test suites are reported to the test 5 5 ; runner. The `MGutGUIRunner` displays the results in an interactive GUI. 6 ; 7 ; :Private: 6 8 ;- 7 9 -
trunk/src/mguthtmlrunner__define.pro
r104 r112 4 4 ; Results for tests, test cases, and test suites are reported to the test 5 5 ; runner. The `MGutHTMLRunner` displays the results in the output HTML file. 6 ; 7 ; :Private: 6 8 ;- 7 9 -
trunk/src/mgutjunitrunner__define.pro
r107 r112 26 26 ; </testsuite> 27 27 ; </testsuites> 28 ; 29 ; :Private: 28 30 ;- 29 31 -
trunk/src/mguttestcase__define.pro
r107 r112 2 2 3 3 ;+ 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 8 41 9 42 ;+ … … 27 60 ;+ 28 61 ; Set this test to be skipped. 62 ; 63 ; :Private: 29 64 ;- 30 65 pro mguttestcase::skip … … 38 73 ; This is a safe place to actually run a single test. Any errors that occur 39 74 ; are assumed to be from the test and recorded as a failure for it. 75 ; 76 ; :Private: 40 77 ; 41 78 ; :Returns: … … 75 112 ; Run setup method before each test. 76 113 ; 114 ; :Private: 115 ; 77 116 ; :Keywords: 78 117 ; fail : out, optional, type=boolean … … 98 137 ; Run teardown method before each test. 99 138 ; 139 ; :Private: 140 ; 100 141 ; :Keywords: 101 142 ; fail : out, optional, type=boolean … … 119 160 120 161 ;+ 121 ; Removes the given prefix from the msgif present.162 ; Removes the given `prefix` from the `msg` if present. 122 163 ; 164 ; :Private: 165 ; 123 166 ; :Params: 124 167 ; msg : in, required, type=string … … 139 182 ;+ 140 183 ; Display test results via test runner methods. 184 ; 185 ; :Private: 141 186 ;- 142 187 pro mguttestcase::display … … 167 212 ; Run the tests for this class (i.e. methods with names that start with 168 213 ; "test"). 214 ; 215 ; :Private: 169 216 ;- 170 217 pro mguttestcase::run … … 258 305 ; Find the name and number of tests (i.e. methods with names that start with 259 306 ; "test"). 307 ; 308 ; :Private: 260 309 ;- 261 310 pro mguttestcase::findTestnames … … 284 333 ;+ 285 334 ; Get properties of the object. 286 ;287 ; :Keywords:288 ; npass : out, optional, type=integer289 ; number of passing tests290 ; nfail : out, optional, type=integer291 ; number of failing tests292 ; nskip : out, optional, type=integer293 ; number of skipped tests294 ; ntests : out, optional, type=integer295 ; number of tests296 ; testnames : out, optional, type=strarr297 ; array of method names which begin with "test"298 335 ;- 299 336 pro mguttestcase::getProperty, npass=npass, nfail=nfail, nskip=nskip, $ … … 312 349 ; Test suites can contain other test suites or test cases. The level is the 313 350 ; number of layers down from the top most test suite (level 0). 351 ; 352 ; :Private: 314 353 ; 315 354 ; :Params: -
trunk/src/mguttestrunner__define.pro
r91 r112 5 5 ; runner. Each subclass of MGutTestRunner displays them in some way. 6 6 ; MGutTestRunner itself is abstract and shouldn't be instantiated. 7 ; 8 ; :Private: 7 9 ;- 8 10 -
trunk/src/mguttestsuite__define.pro
r107 r112 5 5 ; and add test suites/test cases in its `init` method or create an 6 6 ; `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` 7 51 ;- 8 52 … … 11 55 ; Recompile the class definition before creating the object to make sure it is 12 56 ; the newest definition (convenient when making changes to a test). 57 ; 58 ; :Private: 13 59 ; 14 60 ; :Params: … … 34 80 ; it. 35 81 ; 82 ; :Private: 83 ; 36 84 ; :Returns: 37 ; obj 85 ; object 38 86 ; 39 87 ; :Params: … … 67 115 ; Recompiles all test cases contained by the suite or contained by child 68 116 ; suites. 117 ; 118 ; :Private: 69 119 ;- 70 120 pro mguttestsuite::recompileTestCases … … 84 134 ;+ 85 135 ; Display test results via test runner methods. 136 ; 137 ; :Private: 86 138 ;- 87 139 pro mguttestsuite::display … … 110 162 ;+ 111 163 ; Run the contained test suites or test cases. 164 ; 165 ; :Private: 112 166 ;- 113 167 pro mguttestsuite::run … … 158 212 ; set to add all the files in the current directory that end in 159 213 ; "_ut__define.pro" (the current directory is defined to be the 160 ; directory where the method call sthis method is located)214 ; directory where the method calling this method is located) 161 215 ;- 162 216 pro mguttestsuite::add, tests, all=all … … 232 286 ;+ 233 287 ; Get properties of the object. 234 ;235 ; :Keywords:236 ; name : out, optional, type=string237 ; name of the object238 ; npass : out, optional, type=integer239 ; number of passing tests contained in the hierarchy below this object240 ; nfail : out, optional, type=integer241 ; number of failing tests contained in the hierarchy below this object242 ; nskip : out, optional, type=integer243 ; number of skipped tests contained in the hierarchy below this object244 ; ntestcases : out, optional, type=integer245 ; number of directly contained test suites or test cases246 ; ntests : out, optional, type=integer247 ; number of tests contained in the hierarchy below this object248 288 ;- 249 289 pro mguttestsuite::getProperty, name=name, $ … … 275 315 ; number of layers down from the top most test suite (level 0). 276 316 ; 317 ; :Private: 318 ; 277 319 ; :Params: 278 320 ; level : in, required, type=integer … … 311 353 ; home : in, optional, type=string, default='' 312 354 ; 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 317 357 ;- 318 358 function mguttestsuite::init, name=name, home=home, test_runner=testRunner, $ -
trunk/src/mgutxmlrunner__define.pro
r108 r112 4 4 ; Results for tests, test cases, and test suites are reported to the test 5 5 ; runner. The `MGutXMLRunner` displays the results in the output XML file. 6 ; 7 ; :Private: 6 8 ;- 7 9
