concept test in category ios

appears as: tests, tests, test
iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

  • Because you want to test sorting by title in this method, set the sortOrder property in the BooksManager to title.
    booksManager.sortOrder = .title
    Great, so your test method is set up, but how does it perform a test? To create a test, first consider what you’re expecting as the correct result. In this case, after sorting by title, you would expect that the books array will be sorted in a certain order: “Gulliver’s Travels,” “The Da Vinci Code,” then “The Odyssey.” In Xcode, you express this expectation with what’s called an assertion. The basic assertion is expressed with the XCTAssert method. This method requires a Boolean expression—if it returns true, the test has passed. Conversely, if it returns false, the test has failed.
  • Hover over this diamond, and it should become a Play button. Click on this Play button, and the test method you just created should run. If the test is successful, the diamond will display a green tick, while an unsuccessful test will display a red cross (see figure 15.32). Several assertion methods expand on the basic XCTAssert method, performing various common test assertions such as equality, inequality, greater than, less than, and so on.