Difference between revisions of "Testing Tool (Specification)"

(Added "under construction" note)
(Export rules for testin classes)
Line 8: Line 8:
 
=== Add unit/system level tests ===
 
=== Add unit/system level tests ===
  
Semantically there is no difference between unit tests and system level tests. This way all tests can be written in Eiffel. A test is a routine in a class inheriting from '''TEST_SET'''. Test routines must be exported to any and have the prefix '''test'''.
+
Semantically there is no difference between unit tests and system level tests. This way all tests can be written in Eiffel in a conforming way.
 +
 
 +
A test is a routine having the prefix '''test''' in a class inheriting from '''TEST_SET'''. In general features in classes specifically used for testing should be exported at most to {TESTING_CLASS}. This is to prevent testing code from remaining in a finalized system. If you write a helper class for your test routines, let it inherit from '''TESTING_CLASS''' (Note: '''TEST_SET''' already inherits from '''TESTING_CLASS'''). Additionally you should make leaf test sets frozen and make sure you never directly reference testing classes in your project code.
 +
 
  
 
Example unit tests '''test_append''' and '''test_boolean'''
 
Example unit tests '''test_append''' and '''test_boolean'''
 
<eiffel>
 
<eiffel>
  
class TEST_STRING
+
frozen class TEST_STRING
  
 
inherit
 
inherit
Line 29: Line 32:
 
         end
 
         end
  
feature -- Access
+
feature {TESTING_CLASS} -- Access
  
 
     s: STRING
 
     s: STRING
  
feature -- Test routines
+
feature {TESTING_CLASS} -- Test routines
  
 
     test_append
 
     test_append
Line 60: Line 63:
 
<eiffel>
 
<eiffel>
  
class TEST_MY_APP
+
frozen class TEST_MY_APP
  
 
inherit
 
inherit
Line 66: Line 69:
 
     SYSTEM_LEVEL_TEST_SET
 
     SYSTEM_LEVEL_TEST_SET
  
feature -- Test routines
+
feature {TESTING_CLASS} -- Test routines
  
 
     test_version
 
     test_version

Revision as of 10:44, 6 June 2008


Construction.png Not Ready for Review: This Page is Under Development!


Main functionalities

Add unit/system level tests

Semantically there is no difference between unit tests and system level tests. This way all tests can be written in Eiffel in a conforming way.

A test is a routine having the prefix test in a class inheriting from TEST_SET. In general features in classes specifically used for testing should be exported at most to {TESTING_CLASS}. This is to prevent testing code from remaining in a finalized system. If you write a helper class for your test routines, let it inherit from TESTING_CLASS (Note: TEST_SET already inherits from TESTING_CLASS). Additionally you should make leaf test sets frozen and make sure you never directly reference testing classes in your project code.


Example unit tests test_append and test_boolean

frozen class TEST_STRING
 
inherit
 
    TEST_SET
        redefine
            set_up
        end
 
feature {NONE} -- Initialization
 
    set_up
        do
            create s.make (10)
        end
 
feature {TESTING_CLASS} -- Access
 
    s: STRING
 
feature {TESTING_CLASS} -- Test routines
 
    test_append
        require
            set_up: s /= Void and then s.is_empty
        do
            s.append ("12345")
            assert_string_equality ("append", s, "12345")
        end
 
    test_boolean
        require
            set_up: s /= Void and then s.is_empty
        do
            s.append ("True")
            assert_true ("boolean", s.is_boolean and then s.to_boolean)
        end
 
end


Example system level test test_version (Note: SYSTEM_LEVEL_TEST_SET inherits from TEST_SET and provides basic functionality for executing external commands, including the system currently under development):

frozen class TEST_MY_APP
 
inherit
 
    SYSTEM_LEVEL_TEST_SET
 
feature {TESTING_CLASS} -- Test routines
 
    test_version
        do
            run_system_with_args ("--version")
            assert_string_equality ("version", last_output, "my_app version 0.1")
        end
 
end

Manage and run test suite

Create tests automatically

Turn any failed execution into a test

Background test execution

See also