what is a unit test
A unit test is a test that checks the behavior of a single logical unit (usually a class or function) in isolation.
What is continuous integration
Developers work on local machines and merge working code frequently into a shared branch.
On each merge, automatic builds and tests run.
If tests pass → the merge is successful
If tests fail → the merge is blocked
Goal: catch integration issues early and keep the main branch stable.
What is continuous delivery
After CI:
The application is packaged
More tests run (integration, acceptance, performance, etc.)
The system is always in a deployable state
Deployment is manual (someone chooses when to release).
continuous deployment
Continuous deployment is:
CI + CD + automatic deployment
If all tests pass, the application is automatically deployed to production, with no manual approval.
why unit testing
smoke test
a series of core tests that ensures the basic functionality of system is working
doesnt guarantee that theres no bugs just there are no fatal ones so we can do deeper debugging
Critical Factors for Automated Tests
Repeatability & Consistency: Tests should give consistent results every time they run
Readability & Maintainability: Tests act as documentation; keep them simple and understandable.
Testability 2 features
Low control → real database, real network, real services
High control → mocks, stubs, fake databases, test doubles
unit test requirements
3 A’s of unit testing
Arrange - Set up test data and unit under test
act - call the method under test
assert - verify result matches expectation
general rules for unit tests:
Agile test quadrant watch the video for him to explain this this is hard to question but its in the sheet
zcxz
Advantages of test automation
Critical Success Factors for Test Automation
Smart
Self contained and stateless
- should not rely on global state
- tests should be independent and be able to be run in any order
Maintainable
- if you change development code you should easily be able to update tests
Act as documentation
-test name should easily tell us what we are testing
Robust
- minor changes should not cause test to fail
To the point
- test should focus on one thing
- when fails easy to pinpoint error
test driven development
Test-Driven Development (TDD)
Write a test for a functionality
The test should fail (red)
Write just enough code to make the test pass
No extra logic (green)
Refactor the code
Improve code quality while keeping all tests passing
Repeat
Add new tests until no further behaviour is required
example of tdd
TDD Example: isEven(n)
Write a failing test
Test: isEven(2) should return true.
The test fails because the function does not exist.
Write minimal code to pass the test
isEven(n):
return true
The test passes, but the implementation is clearly incorrect.
Add another test
Test: isEven(3) should return false.
This test now fails.
Improve the implementation
isEven(n):
return n % 2 == 0
Both tests now pass.
Refactor (if necessary)
The code is already simple and clear, so no further refactoring is needed.
benefits of tdd
disadvantages of tdd