Database Reference
In-Depth Information
NSException *exception =
[NSException
exceptionWithName:
@"Missing Argument Exception"
reason:@"An argument was missing"
userInfo:nil];
@throw exception;
}
if ([endDate compare:startDate] == NSOrderedAscending) {
NSException *exception =
[NSException exceptionWithName:@"Date Order Exception"
reason:@"The start date can not be after the end date"
userInfo:nil];
@throw exception;
}
Now we have some nice juicy argument checking we can use for negative tests. But
since we're optimistic by nature, let's write the positive test first, shown in Example 5-2 .
Example 5-2. Writing positive test cases
NSDate *testStartDate;
NSDate *testEndDate;
-(void) setUp {
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"YY-MM-dd"];
testStartDate = [df dateFromString:@"2011-08-01"];
testEndDate = [df dateFromString:@"2011-08-02"];
}
-(void) testGetForecastWebServiceEndpointSuccess {
NSURL *url =
[WebServiceEndpointGenerator
getForecastWebServiceEndpoint:@"03038"
startDate:testStartDate
endDate:testEndDate];
STAssertNotNil(url, @"No URL returned");
NSString *correctURL = @"";
NSString *urlString = [url absoluteString];
STAssertEqualObjects(@"", urlString,
@"The generated URL, %@, did not match the \
expected URL,
%@", urlString, correctURL);}
Breaking this down, we start by defining two variables to hold a start and end date,
since we'll be using them in a lot of the test cases, and we don't want to have to create
them fresh in each one. Every test case class has a setUp and tearDown method that you
can override, which will be run before the test cases start and after they end, respec-
tively. It's a good place to make sure all your state is reset, and to initialize common
data that will be needed by the class. We can place our code to create good test dates
there.
 
Search WWH ::




Custom Search