Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS testing with XCTest and separate file

Tags:

ios

xctest

Currently, I write my testing in 1 file (default). Is it possible to have multiple files and test?

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // This is an example of a functional test case.
    XCTAssert(YES, @"Pass");
}
like image 207
Khant Thu Linn Avatar asked Mar 12 '23 16:03

Khant Thu Linn


1 Answers

You can have many files and many tests per file. The first one is just the one made by Xcode automatically, but all that makes it special is that it:

  1. Implements a subclass of XCTestCase
  2. Is a member of the testing target (not your app target)

Making another file with the same characteristics is simple.

In Xcode, File -> New -> iOS -> Source -> UI Test Case Class

The convention is to group related tests into a source file, and then name that source file ___Tests.swift (or .m)

For example, SharingTests.swift might contain the methods testSharingToFacebook() and testSharingToTwitter().

like image 165
divergio Avatar answered Mar 31 '23 05:03

divergio