Skip to content

Commit d340ac6

Browse files
committed
Updated Unit Test Error messages
1 parent c05dca8 commit d340ac6

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

source/ios/AdaptiveCards/ADCIOSVisualizer/ADCIOSVisualizerTests/ADCIOSVisualizerTests.mm

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,35 +200,56 @@ - (void)parseAndRenderDFS:(NSString *)rootPath FileManager:(NSFileManager *)fMan
200200
if ([_setOfExpectedToFailFiles containsObject:fileName]) {
201201
XCTAssertFalse(cardParseResult.isValid);
202202
} else {
203-
if (!cardParseResult.isValid) {
204-
NSException *e = [NSException exceptionWithName:@"ParseFailed" reason:@"Parsing Failed" userInfo:nil];
205-
@throw e;
206-
}
207-
XCTAssertTrue(cardParseResult.isValid);
203+
[self assertParsing:cardParseResult fileName:fileName];
208204
ACRRenderResult *renderResult;
209205
@try {
210206
renderResult = [ACRRenderer render:cardParseResult.card
211207
config:nil
212208
widthConstraint:300
213209
delegate:nil];
214-
XCTAssertTrue(renderResult.succeeded);
210+
[self assertRendering:renderResult fileName:fileName];
215211
}
216212
@catch (NSException *exception) {
217-
NSString *exceptionMessage = [NSString stringWithFormat:@"%@", exception];
218-
printf("Render Failed while rendering %s\n%s", [fileName UTF8String], [exceptionMessage UTF8String]);
219-
XCTAssertTrue(NO);
213+
XCTMutableIssue *issue = [[XCTMutableIssue alloc] initWithType:XCTIssueTypeAssertionFailure compactDescription:@"Rendering Exception"];
214+
[self attachDataToIssueAndRecord:fileName issue:issue];
220215
}
221216
}
222217
}
223218
@catch (NSException *exception) {
224-
printf("Parsing Failed %s\n", [fileName UTF8String]);
225-
for (NSError *parseError in cardParseResult.parseErrors) {
226-
printf("%s\n", [parseError.userInfo[NSLocalizedDescriptionKey] UTF8String]);
227-
}
228-
XCTAssertTrue(NO);
219+
[self assertParsing:cardParseResult fileName:fileName];
229220
}
230221
}
231222
}
223+
224+
- (void)attachDataToIssueAndRecord:(NSString *)fileName issue:(XCTMutableIssue *)issue
225+
{
226+
NSData *data = [fileName dataUsingEncoding:NSUTF8StringEncoding];
227+
[issue addAttachment:[XCTAttachment attachmentWithData:data]];
228+
[self recordIssue:issue];
229+
}
230+
231+
- (void)assertParsing:(ACOAdaptiveCardParseResult *)parseResult fileName:(NSString *)fileName
232+
{
233+
if (!parseResult.isValid) {
234+
XCTMutableIssue *issue = [[XCTMutableIssue alloc] initWithType:XCTIssueTypeAssertionFailure compactDescription:@"Object Model Parsing Failure"];
235+
236+
NSMutableArray<NSString *> *errorMsgs = [[NSMutableArray alloc] init];
237+
for (NSError *parseError in parseResult.parseErrors) {
238+
[errorMsgs addObject:parseError.userInfo[NSLocalizedDescriptionKey]];
239+
}
240+
241+
[self attachDataToIssueAndRecord:[NSString stringWithFormat:@" %@ in %@", [errorMsgs componentsJoinedByString:@", "], fileName] issue:issue];
242+
}
243+
}
244+
245+
- (void)assertRendering:(ACRRenderResult *)renderResult fileName:(NSString *)fileName
246+
{
247+
if (!renderResult.succeeded) {
248+
XCTMutableIssue *issue = [[XCTMutableIssue alloc] initWithType:XCTIssueTypeAssertionFailure compactDescription:@"Rendering Failure"];
249+
[self attachDataToIssueAndRecord:fileName issue:issue];
250+
}
251+
}
252+
232253
- (void)testParsingAndRenderingAllCards
233254
{
234255
NSBundle *main = [NSBundle mainBundle];

0 commit comments

Comments
 (0)