Testing and Delivering
Advanced
30 min read
Lesson 5 of 5
Why Testing Matters
Testing ensures quality, catches bugs early, and builds confidence in your application.
Types of Testing
1. Unit Testing
Testing individual components in isolation.
// xUnit Example
[Fact]
public void Add_TwoNumbers_ReturnsSum()
{
// Arrange
var calculator = new Calculator();
// Act
var result = calculator.Add(5, 3);
// Assert
Assert.Equal(8, result);
}
2. Integration Testing
Testing how components work together.
3. Functional Testing
Testing the application from a user perspective.
4. Performance Testing
- Load testing
- Stress testing
- Scalability testing
5. Security Testing
- Vulnerability scanning
- Penetration testing
- Security audits
Test-Driven Development (TDD)
The TDD Cycle
1. Write a failing test (Red)
2. Write the minimum code to make it pass (Green)
3. Refactor the code (Refactor)
4. Repeat
Continuous Integration (CI)
CI Pipeline Steps
# GitHub Actions Example
name: CI Pipeline
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '10.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release
- name: Run tests
run: dotnet test --configuration Release --verbosity normal
Deployment and Delivery
Deployment Strategies
- Blue-Green Deployment: Two identical environments
- Canary Deployment: Gradual rollout to users
- Rolling Deployment: Update instances one by one
- Feature Flags: Toggle features on/off
Deployment Checklist
# Pre-Deployment
- [ ] All tests pass
- [ ] Code review completed
- [ ] Version number updated
- [ ] Database migrations ready
# Deployment
- [ ] Database backup created
- [ ] Application deployed
- [ ] Health check passes
# Post-Deployment
- [ ] Smoke tests run
- [ ] Monitoring active
- [ ] Logs checked
Key Takeaway
Comprehensive testing and smooth deployment processes ensure high-quality, reliable software delivery.
Exercise
- Write unit tests for a service class
- Create a CI pipeline configuration
- Define a deployment strategy
- Create a deployment checklist