Show/Hide Toolbars

Unit Test Framework Manual

Navigation: » No topics above this level «

Writing Test Cases

Scroll Prev Top Next More

To prepare a test case, you write Gosu code using Guidewire Studio.  Each test case is a Gosu class which follows certain naming conventions.  The class is a subclass of unittestcase.TestCase. The class contains functions that execute tests.  Each function is a separate test.  Each test has a name beginning with test.

 

Example

This is a simple test case that shows the required syntax for a test case:

 

package unittestcase

uses unittestcase.TestCase

 

class SampleTestCase extends TestCase {

 

  construct() {

 

  }

 

  public function testExample() : void {

     assertTrue(true, "true not recognized")

     print("example test") 

  }

  

  public function testExample2() {

    fail("this test case always fails")

  }

}

 

The first line of the example specifies the package This example is provided in the same package as the Unit Test Framework.  You should put your test cases into your own package.

 

The next line is a uses statement that identifies the TestCase class that your test case will subclass.

 

The framework will execute each function beginning with the string test. Each test function typically performs checks using one or more of the assertion functions.  An assertion checks the first argument of the function.  If the argument is true, the assertion simply continues.  If the argument is false, the function throws an AssertionException.  The framework catches these exceptions and reports the results.

 

TestCaseInBundle

If your tests update entities in the Guidewire application, you should consider using the superclass TestCaseInBundle, instead of TestCase. TestCaseInBundle wraps each sequence of setUp(), test...(), and tearDown() in a transaction with its writable bundle.  When using this superclass, you do not need to execute tests in the Gosu Scratchpad using Transaction.runWithNewBundle().  

 

Test Suites

You can group test cases together in test suites to make running multiple test cases easier.

 

Additional Information

Assertions

Executing Test Cases

Reporting Test Results

Special Functions

Checking Exceptions

Writing Test Suites