FresherTesting FundamentalsFree question
What are the levels of testing?
60-second answer
There are four main levels. Unit testing checks the smallest pieces of code, like a single function, usually by developers. Integration testing checks that modules work together, for example the UI calling an API that writes to a database. System testing checks the complete, integrated application against requirements, end to end. And acceptance testing, or UAT, is done by the business or users to confirm the system is ready for real use. Each level catches different kinds of defects.
Explanation
- Unit: fast, isolated, written by developers (JUnit, pytest).
- Integration: interfaces and data flow between components. Approaches: big-bang, top-down (stubs), bottom-up (drivers).
- System: functional and non-functional testing of the whole product in a production-like environment.
- Acceptance (UAT): business validation. Includes alpha (in-house) and beta (real users) testing.
This maps to the test pyramid: many unit tests, fewer integration tests, and even fewer end-to-end UI tests.
Example
Banking app transfer feature:
- Unit:
calculateFee(amount)returns 0 for amounts under 1000. - Integration: transfer service correctly debits account A and credits account B in the DB.
- System: user logs in, transfers money, sees the updated balance and gets an SMS.
- UAT: a branch manager confirms the flow matches bank rules.
Sample code
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class FeeCalculatorTest {
@Test
void noFeeForSmallTransfers() {
assertEquals(0, new FeeCalculator().calculateFee(999));
}
}