!--a11y-->
Test SetsA test set is a java class that extends com.sap.tc.jtools.jver.framework.Test (or com.sap.tc.jtools.jver.framework.JverTestVC, which provides additional convenience methods) and contains Test in its name. For example, the simplest test set is:
|
public class EmptyTest extends com.sap.tc.jtools.jver.framework.Test {} |
A test set consists of the:
· test fixture
· test methods
· specification of test attributes
The fixture is a set of objects which is available to all tests inside the test class. The provision of the test fixture is supported by the inherited methods prepare and cleanUp. You add the objects as instance variables, then initialize them in the prepare method. If necessary, clean up tasks in the cleanUp method.
Test method names must start with test. A test flops when a verification proves false, a direct flop is called, or an exception is thrown.
You perform the actions you want to test and verify your assumptions by calling the verify method. In addition to specifying a Boolean condition and the relevant message that will be displayed when the condition is false, you can, for each verify method, specify how JVer reacts to a false condition:
· TOLERANT- the current test method will be continued.
· CRITICAL- the current test method will be abandoned.
· FATAL - the current test class will be abandoned.
A test flops if a flop method is executed. Therefore, you can use flop to verify that code branches inside your test code are not reached. You would typically put a flop method in a branch of code that should not be executed if the program works as expected. As with the verify method, you can specify how JVer reacts to a flop.
Usually, you need not catch exceptions in test methods. Instead, just extend the signature of the test method by the relevant throws clause. The JVer framework will then take care of the exception – a thrown exception from a test method is treated in the same way as a failed verification. Thus a complete test method does not necessarily need a call to either one of the verify or flop methods.
There are occasions when you want to catch exceptions, for example, if you want to:
· verify their presence
· pass them to the framework with a verification level other than CRITICAL. In this case, you would catch the exception and pass it using the appropriate flop method.
Each test class has a set of associated attributes. The test attributes determine the behavior of the test class execution and specify additional data. The test attributes exist before the actual test class is instantiated because the moment of instantiation and the number of instantiations can depend on them. If the default attribute settings fit your needs, the attributes will not appear in your test class implementation. However, if want to adjust the test attributes to your specific needs, add a static method to your test class as follows:
|
public static void adjustTestAttributes(IJverTestAttributes attributes) {} |
The interface of the type com.sap.tc.jtools.jver.framework.IJverTestAttributes gives you access to all the setter methods for the attribute's members that you might need to adjust. For example, you can specify:
· whether the fixture embraces the whole test set (default) or each test method individually
· whether a new test object is instantiated for each test method
· which test methods are to be executed
Parameters allow you to parameterize tests. Parameters which are used inside a test class must be defined by the method defineParameters. The values assigned here serve as default values. If a value is not specified (which is not recommended), an empty string will be the default. The separator between a key and its value can be an equal sign, a colon, or a whitespace character. For example:
|
attributes.defineParameters ( new String [] { "test.number=-1", "test.system=ABC" }); |
You get parameters from within a test using the method getParameter. For example:
|
String system = getParameter("test.system"); |
You specify parameter values in a separate properties file ( filename.properties). For example:
|
test.number=1 test.system=XYZ |
