Contains notes on software testing.
There are various types of testing, like Unit, Integration and Functional(E2E) testing.
- Unit Testing -> For testing any small piece of code
- Integration Testing -> For testing any small component of the application
- Functional Testing -> For testing the complete flow of the application(Basically automating the manual testing/ replicating the user actions)
- Generally for testing small piece of code, isolated and alone.
- If writing unit test is hard then it means your code is poorly designed. So it also helps in writing better code.
- They are also great for preventing regressions - bugs that occur repeatedly.
- Unit testing is used in TDD. Its like a backbone.
- If an app needs to make a successful database connection then it can't be tested with unit testing.
- In procedural code, the units are often functions, in object oriented code, the units are classes.
- They are fast + cheap.
- Its to test how parts of the system work together - the integration of the parts.
- It's similar to unit test with one difference: while unit tests are isolated from other components, integration tests are not.
- They are complex and slower compared to unit test.
- You should have fewer integration test compared to unit test.
- If an app needs to make a successful database connection then it can be tested in integration testing.
- They are slow + expensive
- Testing the complete functionality of the application by using some tool to automated a browser/mobile.
- Do not make them fine-grained, as they can become a nightmare to maintain.
- They are used when you want to test a complete flow like registering a user, making a payment and redirecting to proper pages, etc
- They are slow + expensive
- They require less maintenance and cover a bigger part of your application with saving you a lot of time.
There are three types on android
- Unit(test) - JUnit5/ Mockito
- Intrumentation(androidTest) - JUnit/ Mockito
- UI(androidTest) - Expresso(Internal)/ Appium(External)
- Runs on Local Computer
- It runs on JVM
- Very fast because emulator is not needed.
- It's for testing java code
- Similar to local unit tests
- Used for testing android specific stuff like activity, fragments, context, serviecs, etc
- Need to run on real device or emulator(Roboelectric is used if you don't want to run it on emulator)
- Simulates the user flow
- Tests the complete user journey from high level
- Mocks the RestAPI/Database part in the methods/functions
Criteria | Espresso | Appium |
---|---|---|
Language | Java | Many(Java, Python, Javascript, any that can make HTTP request) |
Supports | Android Only | Web, Android and iOS |
Testing Philosopy | Grey Box | Black Box |
Speed | Fast | Slow compared to Espresso |
Ease Of Setup | Easy | Hard |
Dependencies On Code | Yes | No |
Ease Of Writing Tests | Easy for devs | Easy for testers |
Backers | Goolge | Open Source |
Suitable For | Android devs | Testers/ QA testing Android & iOS apps |