Software Testing, TDD, and BDD
Why Test?
Testing ensures software quality and reliability by detecting errors early in the development lifecycle.
Causes of Errors:
- Miscommunication of requirements
- Poorly understood features
- Human errors in logic or syntax
- Integration conflicts
Types of Software Testing
1. Unit Testing
- Tests individual components or units of code (e.g., a function or method).
- Focuses on internal logic.
2. Integration Testing
- Tests the interaction between units or modules.
- Helps ensure that components work together properly.
3. Regression Testing
- Ensures that new code does not break existing functionality.
- Important when code is refactored or updated.
4. Use Case Testing
- Tests if the application behaves correctly based on user scenarios or workflows.
5. User Acceptance Testing (UAT)
- Confirms whether the system meets the requirements of the end user.
- Includes subjective and objective test cases.
- Typically the final phase before deployment.
6. Performance Testing
- Assesses how a system performs under load, volume, stress, and endurance.
- Load testing
- Volume testing: Mainly focuses on databases
- Endurance testing: Testing the sustainability of the system under continued load
- Stress testing
- Analyze post-crash reports to define the behavior of the application after failure.
- Ensure that the system does not compromise the security of sensitive data after the failure.
- Load testing
UAT Deliverables
- Test Plan: Strategy, criteria, and roles
- Test Cases: Step-by-step instructions
- Test Log: Record of executed tests and results
- User Sign-Off: Final approval confirming the product meets expectations
How to Conduct UAT – AltexSoft
Why Automate Unit Testing?
- Saves time on repeated tests
- Ensures tests are run consistently
- Enables quick bug detection and fixes
- Facilitates continuous integration
How It Works
- Determine the expected output
- Compute the actual output
- Compare them → Pass or Fail
Popular Frameworks
Test-Driven Development (TDD)
"Write tests before you write your code.”
TDD Cycle:
- Write a failing test
- Write the minimal code to pass the test
- Refactor the code
- Repeat
Benefits:
- Leads to modular, reusable code
- Encourages thinking from the user’s perspective
- Reduces bugs and improves test coverage
Behavior-Driven Development (BDD)
BDD is a refinement of TDD. It focuses on natural language descriptions of software behavior.
Structure:
- GIVEN some initial context
- WHEN an event occurs
- THEN ensure some outcome
Example:
GIVEN: User is on the Google homepage
WHEN: User searches for “BDD”
THEN: Results for “BDD” are displayed
Advantages:
- Improves communication across stakeholders
- Ensures clarity of requirements
- Makes test automation easier
Reflection Questions
- List 3 benefits of rigorous testing.
- Identify testing methods that can be automated.
- When should testing be done in the development cycle?
- What is the primary goal of integration testing?
- Which testing ensures older features still work after new ones are added?
- What is black-box testing?
Summary
- Testing is essential for delivering high-quality, bug-free software.
- TDD ensures your code is written with testing in mind.
- BDD helps bridge the gap between technical and non-technical team members.
- Automation frameworks make testing scalable and reliable.
Disclaimer: Generative AI was used in part to generate these lecture notes.