April 2020
Beginner
316 pages
8h 20m
English
Now that we're set up, let's get straight into it and start writing our first Unit Test. Copy the following into your test class (you can remove testExample()):
func testIfGetCountriesHasItems() { XCTAssertTrue(Helper.getCountries().count > 0)}
We'll start with something nice and simple. Inside our Helper method, we have a function called getCounties() that we'll always need to return an array of countries for our app to work. So, with the use of XCAssertTrue, we can write a very quick one-liner Unit Test that checks if our helper function actually returns some results.
We can also write this like so:
XCTAssertGreaterThan(Helper.getCountries().count, 0)
Using the XCTAssertGreaterThan assertion allows us to ...
Read now
Unlock full access