Practical exercises for unit testing in CI/CD pipelines (Windows Edition)
Duration: 4 hours | Module: Testing & Artifacts
Replace the entire content with:
Save and close (Ctrl+S, Alt+F4)
Add this code:
Save and close
Add complete test class:
Save and close
@Test - Marks method as a test@BeforeEach - Runs before each test@DisplayName - Descriptive test nameassertEquals(expected, actual) - Check equalityassertThrows(exception, code) - Check exception thrownassertTrue(condition) - Check booleantarget\surefire-reports\TEST-*.xml
target\surefire-reports\*.txt
Add this test at the end of the class:
Save and close
Change the assertion to correct value:
Or remove the test entirely, then run mvn test again.
Add this code:
Save and close
Add comprehensive tests:
Save and close
Add complete pipeline:
Save and close
/azure-pipelines.ymlYou'll see:
Add .NET test pipeline:
Save, commit, and push to Azure Repos
You'll see:
Click on any test to see:
Use filters to:
Add this failing test:
Change the assertion to correct value:
Commit and push:
| Issue | Solution |
|---|---|
| Maven tests not found |
Check test location: src\test\javaVerify test class ends with "Test" Ensure methods have @Test annotation |
| .NET tests not running |
Check project name ends with ".Tests" Verify [Fact] or [Theory] attributes Run: dotnet test --list-tests
|
| Tests pass locally, fail in pipeline |
Check Java/.NET version matches Remove hardcoded paths or timestamps Ensure tests are independent |
| Test results not showing in Azure DevOps |
Verify publishJUnitResults: true (Maven) Verify publishTestResults: true (.NET) Check test results file path is correct |
| Build passes despite test failures |
Remove continueOnError: true from YAML Ensure test task doesn't have condition: always() Check Maven/dotnet commands are correct |
You've successfully automated testing in CI/CD pipelines!
Ready for Day 13: Code Coverage & Test Reporting