Interview Questions and Answers in iOS — Part 9
Interview questions and answers in iOS in very simple language.
Q. What is unit testing?
A. Unit tests are automated tests that run and validate a piece of code (known as the “unit”) to make sure it behaves as intended and meets its design.
Unit tests have their own target in Xcode and are written using the XCTest framework. A subclass of XCTestCase
contains test methods to run in which only the methods starting with “test” will be parsed by Xcode and available to run.
Q. What is the Test Driven Development of three simple rules?
A. 1. We are not allowed to write any production code unless it is to make a failing unit test pass.
2. We are not allowed to write any more of a unit test than is sufficient to fail, and compilation failures are failures.
3. We are not allowed to write any more production code than is sufficient to pass the one failing the unit test.
Q. What is RGR ( Red — Green — Refactor)?
A. Red, Green, and Refactor are stages of the TDD (Test Driven Development).
1. Red: Write a small amount of test code usually no more than seven lines of code and watch it fail.
2. Green: Write a small amount of production code. Again, usually no more than seven lines of code and make our test pass.
3. Refactor: Tests are passing, we can make changes without worrying. Clean up our code.
Q. What’s Code Coverage?
A. Code coverage is a metric that helps us to measure the value of our unit tests.
Q. Please explain “Arrange-Act-Assert”?
A. AAA is a pattern for arranging and formatting code in Unit Tests. If we were to write XCTests each of our tests would group these functional sections, separated by blank lines:
- Arrange all necessary preconditions and inputs.
- Act on the object or method under test.
- Assert that the expected results have occurred.
Q.
Thank you for reading! If you liked this article, please clap to get this article seen by more people.
Please follow me on Medium by clicking Follow.
I’m also active on LinkedIn, Twitter, and GitHub.