...
For repetitive testing of degenerate use of methods with null and empty values, a class DegenerateUseMethodTestHelper is provided.
To use the degenerate test helper:
References/Links
For repetitive testing of degenerate use of methods with null and empty INVALID values, a class DegenerateUseMethodTestHelper is provided, which includes two static methods
- DegenerateUseMethodTestHelper(Object o, Method , Parameters, ExpectedFailuresm, Object[] parameters)
- DegenerateUseMethodTestHelper(Object o, Method , Parametersm, Object[] parameters, ExpectedFailures[] failureTypes)
where:
- Object: The service client undergoing testing
- Method: The method of the service client to be tested
- Parameters: An object array of values that that produce successful invocation of the method
- ExpectedFailures: An ExpectedFailure array specifying the degenerate behavior array of Enum constants ExpectedFailures
- The most common types used will be:
- EXCEPTION
- Null and invalid values both throw exceptions.
- If the ExpectedFailures array is not specified, this is the default behavior
- SKIP
- Behavior of this parameter will not be evaluated
- NONE
- Null and invalid values should not throw exceptions
- NO_RESULTS
- Null and invalid values will both return no results
- EXCEPTION
- Type-specific behavior: Here, differing behavior is expected from invalid and null values. The following enums are named in the format TYPE_PARAMETER1_RESULT1_PARAMETER2_RESULT2. For each of these cases, the parameter passed in is checked for type safety, and behavior evaluated according to the result for each parameter.
- NONE,
- EXCEPTION,
- SKIP,
- Class: Long
- Invalid value is -5L;
- Available enums are:
- LONG_INVALID_NO_RESULTS_NULL_EXCEPTION
- For an invalid Long value, no results should be returned
- For a null Long value, an exception should be thrown
- LONG_INVALID_NO_RESULTS_NULL_EXCEPTION
- Class: String
- Invalid value is "";
- Available enums are:
- STRING_
- INVALID_EXCEPTION_NULL_EXCEPTION
- For both INVALID and null String values, an exception should be thrown
- This is identical to EXCEPTION above, but restricted to String parameters
- STRING_
- INVALID_EXCEPTION_NULL_EXCEPTION
- INVALID_EXCEPTION_NULL_NO_RESULTS
- An INVALID string will cause an exception
- A null string will return no results
- STRING_
- INVALID_EXCEPTION_NULL_SUCCESS
- An INVALID string will cause an exception
- A null value will cause a successful invocation
- STRING_
- INVALID_NO_RESULTS_NULL_EXCEPTION
- An INVALID string will return no results
- A null value will throw an exception
- STRING_
- INVALID_NO_RESULTS_NULL_NO_RESULTS
- Both INVALID strings and null values return no results.
- STRING_
- INVALID_NO_RESULTS_NULL_SUCCESS
- An INVALID string will return no results
- A null value will cause a successful invocation
- STRING_
- INVALID_SUCCESS_NULL_EXCEPTION
- An INVALID string will cause a successful invocation
- A null string will throw an exception
- STRING_
- INVALID_SUCCESS_NULL_NO_RESULTS
- An INVALID string will cause a successful invocation
- A null string will return no results
- STRING_
- INVALID_SUCCESS_NULL_SUCCESS
- Both null and INVALID strings will cause a successful invocation
- This is identical to NONE above, but restricted to String parameters
- Class: Long
- The most common types used will be:
Example: Exceptions only
Code Block |
---|
SecurityClientRest service = new SecurityClientRest(ConfigUtility.getConfigProperties()); // use reflection to get the desired method Method method = service.getClass().getMethod( "authenticate", // method name and parameters new Class<?>[] {String.class, String.class}); // i.e. SecurityClientRest.authenticate(String username, String password) // specify the valid parameters Object[] parameters = new Object[] { new String("name"), new String("password") // valid parameters that when passed to method produce successful outcome (e.g. authentication) }; // if all invalid and null parameters should call the helperthrow exceptions, use this call DegenerateUseMethodTestHelper.testDegenerateArguments(service, method, parameters); // if different parameters cause different behavior, use this type of call DegenerateUseMethodTestHelper.testDegenerateArguments(service, method, parameters); |
...
, new ExpectedFailure[] {
ExpectedFailure.STRING_INVALID_NO_RESULTS_NULL_EXCEPTION, // an INVALID string will result in no result, a NULL string will result in exception
ExpectedFailure.EXCEPTION // both INVALID strings and NULL strings will result in exception
}); |
References/Links
...