summaryrefslogtreecommitdiff
path: root/render-test/ios/tests/Tests.m
blob: 0b7f3c99dc8c0a00ef48773e55aa90ae4452924c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#import <XCTest/XCTest.h>
#import "iosTestRunner.h"
@interface Tests : XCTestCase

@end

@implementation Tests

- (void)setUp {
    [super setUp];
}

- (void)tearDown {
    [super tearDown];
}

- (void)testStartRenderTestRunner {
    IosTestRunner* runner = [[IosTestRunner alloc] init]; 
    XCTAssert(runner, @"IOSTestRunner is not initialized correctly");

    NSString* styleResult = [runner getStyleResultPath];
    XCTAssert(styleResult, @"IOSTestRunner does not produce a style test result file");
    NSString* metricResult = [runner getMetricResultPath];
    XCTAssert(metricResult, @"IOSTestRunner does not produce a metric test result file");
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL fileFound = [fileManager fileExistsAtPath: styleResult];
    XCTAssert(fileFound, @"Test result html '%@' doese not exit", styleResult);
    NSURL *styleURL = [NSURL fileURLWithPath:styleResult];
    XCTAttachment *attachment1URL = [XCTAttachment attachmentWithContentsOfFileAtURL: styleURL];
    XCTAssert(attachment1URL, @"Failed to attach test result '%@'", styleResult);
    attachment1URL.lifetime = XCTAttachmentLifetimeKeepAlways;
    [self addAttachment:attachment1URL];

    fileFound = [fileManager fileExistsAtPath: metricResult];
    XCTAssert(fileFound, @"Test result html '%@' doese not exit", metricResult);
    NSURL *metricURL = [NSURL fileURLWithPath:metricResult];
    XCTAttachment *attachment2URL = [XCTAttachment attachmentWithContentsOfFileAtURL: metricURL];
    XCTAssert(attachment2URL, @"Failed to attach test result '%@'", metricResult);
    attachment2URL.lifetime = XCTAttachmentLifetimeKeepAlways;
    [self addAttachment:attachment2URL];

    NSString* metrics = [runner getMetricPath];
    if (metrics && [fileManager fileExistsAtPath: metrics]) {
        NSURL *metricsURL = [NSURL fileURLWithPath:metrics];
        XCTAttachment *attachmentMetricsURL = [XCTAttachment attachmentWithContentsOfFileAtURL: metricsURL];
        XCTAssert(attachmentMetricsURL, @"Failed to attach test rebaselined metrics '%@'", metrics);
        attachmentMetricsURL.lifetime = XCTAttachmentLifetimeKeepAlways;
        [self addAttachment:attachmentMetricsURL];
    }
    else {
        NSLog(@"No rebaselined metrics are found");
    }

    BOOL success = [runner getTestStatus];
    XCTAssert(success, @"IOSTestRunner reports error because some of the tests are not passed, please check the test report");
}

@end