2

In every new project I see the file with the content (and this file belongs to different target ProjectNameTests):

- (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"); } - (void)testPerformanceExample { // This is an example of a performance test case. [self measureBlock:^{ // Put the code you want to measure the time of here. }]; } 

1) How to use this file?

2) How can I test my application with this file? Why it's better then just launching the application and testing it or then to write test code directly in AppDelegate (when I need to test the responce from server for instance)?

3 Answers 3

2

These are called Unit Tests and you can test your components, like classes and functions, with them. You write a Test and if you change something on your classes, the test will show you if the class still works as expected.

For an example: http://www.preeminent.org/steve/iOSTutorials/XCTest/

You should also read a bit about test driven development, it is a nice way of developing and mandatory for most companies.

As a down side on XCode UnitTests i have to tell you that you can't use operations on files within them.

Sign up to request clarification or add additional context in comments.

Comments

1

1) To use that file, you replace the testExample and testPerformanceExample with your own methods that begin with test. For example, if you want to test that your Foo class object returns true for isFoo:

- (void)testFooIsFoo() { Foo f = [Foo new]; XCTAssertTrue([f isFoo], "Foo object should return true for isFoo"); } 

2) Why is this better than manual testing? You can write smaller tests for parts that might be more time consuming to reach in the app. It also allows you to test things in isolation. So, rather than test that the network stack works, these kinds of tests are good for testing that you handle data correctly and so on.

Good testing requires a mix of unit testing (which is what this is) and manual testing.

Apple's documentation is light on the why and what you should unit test. But this is a good article from objc.io about testing this way and how to do it with XCTest.

Comments

0

Apple provide a nice documentation. But if you want to see real code, I have a github project that implements tests.

The main purpose ox XCTests is that you can launch tests from Xcode directly without building and running the program. Xcode provide a nice interface to do that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.