Isolating tests

Assumptions are a huge 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 something happened that made the user log out? ne example is a test that makes sure your user can log out, which would leave the simulator without a logged in user.

When this happens, a lot of your tests will fail due to assumptions that were 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 common pattern that people use to structure their tests and improve reliability is the 3-As or AAA approach. This name of this pattern is short for Arrange, Act, and Assert. The following is an explanation for each of the As.