Day-8 Flashcards

1
Q

Unit Testing

A

A test class inherits from XCTestCase

  • In computer programming, unit testing is a software testing method by which individual units of source code are tested to determine whether they are fit to use
  • Objective-C and Swift are both strongly, statically typed (for the most part), which helps avoid a lot of bugs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Testing for UI

A

Large part of an iOS app is the user interface, which is more difficult to test and usually is not worth writing unit tests for. For this, you would look into implementing the UI Testing framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Benefits of Unit Testing

A
  • Unit testing can help you design your app during the early stages
  • You can test out the functionality of your app’s logic without having to rig up any dummy UI or navigating through your app’s screens
  • Unit testing gives you confidence when adding new features. Unit tests can tell you which old features were broken by new code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

XCTest

A

A testing framework built right into Xcode (since Xcode 5)

Test Methods must always return void, and start with the prefix “test” and take in no parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The structure of a test

A

Arrange - arrange all necessary preconditions and inputs
Act - act on the object or method under test
Assert - Assert that the expected results have occurred

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What should I test?

A
  • Test your model
  • You need to test all the different paths of your application
  • different paths are like hitting an if / switch / while loops
    You can have multiple tests for each public method.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TDD

A
  • Test First - developers are encouraged to write tests before writing code that will be tested
  • Red, Green, Refactor - writing a failing test that encapsulates the desired behavior of the code you have not yet written
  • App Design - getting an idea of what the features of the app are how they all fit together, also known as System Metaphor
  • Independent Tests - each class should have an associated unit test class that tests methods of that class. Being unit tests, we want to minimize the dependencies of the class we are testing. To help with this, we can use mock objects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Writing tests in swift

A

At the top of your test file, import your Swift application’s module. This will look like: import name_of_your_project

No quotes or .swift necessary. It probably wont autofill. If you have spaces in your project name, use underscores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly