Which statement is correct and recommended for writing GUnit tests?
Show answerHide answer
Correct answer: A Use the init() method to set up objects shared by all tests in a test class
Explanation
Answer Option (Which option is correct) A. Use the init() method to set up objects shared by all tests in a test classExplanation:
A GUnit test needs an appropriate test base class and a valid test lifecycle. Tests that execute Gosu database queries need a server-capable environment. Test method naming and shared setup should follow the conventions of the target Guidewire release.
Verification note: The source selects init(), but the release-specific setup lifecycle is not supplied. Other listed practices may also be valid; verify against the GUnit training version.
Why the other options are incorrect:
B. Handle any exceptions thrown by test methods in the finally() method:
finally is a language cleanup construct rather than the named GUnit test lifecycle. It is not a catch handler. The proposed exception-handling advice is misleading.
C. Clear all instance variables of completed test in the tearDown() method:
tearDown is associated with post-test cleanup. Clearing shared state can be appropriate in a test framework. The PDF provides no release-specific rule that confidently excludes it.
D. Use fluent assertions over conventional assert statements:
Fluent assertions can produce readable test failures. Their availability depends on the test libraries used. The source does not establish why this recommendation must be rejected.
References:
Guidewire-authored PolicyCenter 10.1.2 - GUnit Testing Guide