1. What are unit tests?

A: Unit testing is apple’s test environment for us to facilitate the detection of a certain module business! The so-called test environment is another place where we write code. It exists under different folders of our project.

2. How do YOU use unit tests?

A: You can write test code directly in test.m, or create a new test file by yourself.

Of course, you can also create a new unit test class!

XCTAssert is an assertion that you can use to test

When the test passes, there will be a green check mark inside the little circle clicked to prove that the unit test has passed

If a red X appears, the unit test failed

3. So why use this unit test? What benefits does it bring us?

A: In order to save trouble, we usually write some test code directly in the project, such as NSLog, print test assertions and so on. However, if the test code is too much, the project will look messy, and the project volume will become larger. When the test is completed, we have to delete the test code written before. Don’t you think it’s annoying that we’ve worked so hard to write tests that we can delete them when we don’t need them or write them again when we need them? Unit testing, of course, solves all this nicely. Because the code in the test unit doesn’t package into our project, and it doesn’t build the whole project, it just runs. The benefits may not be understood in words, but will be understood in practice.

Pay attention to wechat public number: iOSSir, daily update Apple information, technology dry goods!