Isolating tests

Assumptions are a considerable risk when you're testing. Any time you assume anything about the environment you're testing in, your test is not reliable. If you're just getting into writing tests, it's tempting to make assumptions such as I'm testing on the simulator and my test user is always logged in so my tests can be written under the assumption that a logged-in user exists. This assumption makes a lot of sense to a lot of people, but what if one of your tests logs the current user out?

When this happens, a lot of your tests will fail due to assumptions that you made about the test environment. More importantly, these tests might fail even if the code they're testing works flawlessly.

As mentioned before, tests should test a single thing in your app. They should rely on as little outside code as possible, and they should be properly focused. A typical pattern that people use to structure their tests and improve reliability is the 3-As or AAA approach. The name of this pattern is short for Arrange, Act, and Assert. The following is an explanation for each of the As.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset