Unit testing and TDD Flashcards
What are the levels of testing discussed in the lecture?
Unit Testing and System Testing.
What is Unit Testing?
Unit Testing involves testing individual components or units of a software application to ensure they work correctly.
Who typically performs Unit Testing?
Unit Testing is typically performed by developers on their own code.
What is System Testing?
System Testing involves testing the entire system as a whole to verify that it meets specified requirements.
Who typically performs System Testing?
System Testing is usually carried out by dedicated Test Engineers.
What is JUnit?
JUnit is a unit testing framework for Java, first released in 2002 by Kent Beck, Erich Gamma, David Saff, and Kris Vasudevan.
What version of JUnit introduced modular components?
JUnit 5, released in 2017, introduced modular components.
What is the purpose of the @BeforeEach and @AfterEach annotations in JUnit?
@BeforeEach runs before each test, and @AfterEach runs after each test, commonly used for setup and teardown tasks.
What are characteristics of a good unit test?
A good unit test:
- Has a descriptive name
- Tests one thing
- Always returns the same result
- Has no conditional logic
- Is independent of other tests.
What is code coverage?
Code coverage measures the degree to which the source code is executed when a test suite runs.
What is the recommended code coverage percentage?
At least 80% coverage is recommended, though 100% coverage doesn’t guarantee bug-free code.
What is Test Driven Development (TDD)?
TDD is a software development approach where tests are written before the actual code to guide development.
What are the steps of TDD?
- Write a failing test
- Write skeleton code
- Write enough code to pass the test.
What are the benefits of TDD?
TDD helps build testable code, reduces bugs, and improves code design and maintainability.
What are Test Doubles?
Test Doubles are substitutes for real components in a system used for testing purposes.
What types of Test Doubles exist?
- Dummy Objects
- Test Stubs
- Test Spies
- Mock Objects.
What is the purpose of a Mock Object?
A Mock Object simulates the behavior of a real object and verifies interactions between components.
What is Mockito?
Mockito is a popular Java mocking framework used to create mock objects for testing purposes.
How can you verify interactions using Mockito?
Use the verify method to check if specific methods were called with expected parameters.
What is a Test Pattern?
A Test Pattern provides a reusable solution for common testing design challenges.
What is Dependency Injection in testing?
Dependency Injection involves passing dependencies to a component at runtime to make testing easier.
What is a Dependency Lookup Pattern?
Dependency Lookup involves designing a system to retrieve dependencies at runtime, often using a factory pattern.