Wiki

Changes between Initial Version and Version 1 of Tests

Show
Ignore:
Timestamp:
01/08/13 00:55:38 (12 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Tests

    v1 v1  
     1= Tests = 
     2 
     3Support for provision of (unit) Test code is built into the cobra language. 
     4 
     5Tests are specified as clauses on Class members (methods and properties) or on Class types(?). 
     6 
     7They are given as an indented block of standalone code prefixed by the '''test''' keyword suffix with an optional test name.[[BR]] 
     8The indented code block does the setup for a test (object instantiation and state initialisation), executes the test case (or cases), verifies ( usually by [wiki:Assert assertions]) that the test passes followed by any necessary teardown. 
     9 
     10Tests are executed whenever the program or code is run (unless tests are suppressed at build by the -include-tests:no compiler option).[[BR]] 
     11 
     12Failures how up as an assert failure and a stack trace. 
     13 
     14== Example == 
     15{{{ 
     16#!cobra 
     17class Incrementer 
     18 
     19    var counter =0 
     20    var val = 0 
     21 
     22    test 
     23      incr = Incrementer() 
     24      assert incr.counter == 0 
     25      assert incr.val == 0  
     26      i = incr.bump(2) 
     27      assert i == 2 
     28      assert incr.counter == 1 
     29      assert incr.val == 2 
     30      i = incr.bump(3) 
     31      assert i == 5 
     32      assert incr.counter == 2 
     33      assert incr.val == 5 
     34 
     35 
     36    def bump(inc as int) as int 
     37        test 
     38          incr = Incrementer() 
     39          incr.bump(1) 
     40          assert incr.counter == 1 
     41          assert incr.val == 1 
     42          incr.bump(2) 
     43          assert incr.counter == 2 
     44          assert incr.val == 3 
     45        body 
     46           .counter += 1 
     47           .val += inc 
     48           return .val  
     49}}} 
     50