Java test primitives

All the test primitives described here are available for both J2SE and J2ME versions of the JUnit testing framework.

This section describes each method used by Component Testing for Java, including:

Notation Conventions

Throughout this guide, command notation and argument parameters use the following standard convention:

 

 

Notation

Example

Meaning

BOLD

BEGIN

Language keyword

<italic>

<string>

Symbolic variables

[   ]

[<option>]

Optional items

{   }

{<string>}

Series of values

[{   }]

[{<string>}]

Optional series of variables

|

on | off

OR operator

JUnit Assert Primitives

Component testing for Java uses the standard assert test primitives provided by JUnit. Please refer to documentation provided with JUnit documentation for further information.

 

Method

Purpose

assertEquals()

Checks that two values are equal

assertNotNull()

Checks that an object is not null

assertNull()

Checks that an object is null

assertSame()

Checks that two object are actually the same

assertTrue()

Checks that a condition is true

fail()

Marks a test as Failed

 

Extended Primitives

Component Testing for Java extends the set of assert test primitives provided by JUnit with a special set of verify primitives. These extended test methods are part of the TestCase class. User test classes must derive from TestCase to use these primitives.

 

Method

Purpose

verifyEquals()

Checks that two values are equal

verifyNotNull()

Checks that an object is not null

verifyNull()

Checks that an object is null

verifySame()

Checks that two object are actually the same

verifyTrue()

Checks that a condition is true

verify()

Checks that an exception is thrown

verifyApproxEquals()

Checks that two variables have the same value within a given margin

verifyGreaterThan()

Checks that a tested value is strictly greater than a reference value

verifyGreaterThanEquals()

Checks that a tested value is greater or equal to reference value

verifyLowerThan()

Checks that a tested value is strictly lower than a reference value

verifyLowerThanEquals()

Checks that a tested value is lower or equal to reference value

verifyLogMessage()

Logs a message in the test report

verifyLogfail()

Marks a test as Failed with a message

 

Timer Primitives

Component Testing for Java provides multiple timer control primitives, allowing you to perform basic performance testing.

 

Method

Purpose

createTimer()

Creates a timer

timerStart()

Starts a timer

timerReportElapsedTime()

Logs the elapsed time since a timer was started

verifyElapsedTime()

Checks that the elapsed time for a timer is below a given value