|
1 | 1 | # DB-TimetableAPI-MCPServer |
2 | 2 |
|
| 3 | +[](https://github.com/abeckDev/DB-TimetableAPI-MCPServer/actions/workflows/dotnet-ci.yml) |
| 4 | +[](https://opensource.org/licenses/MIT) |
| 5 | + |
3 | 6 | > **Model Context Protocol (MCP) Server for Deutsche Bahn Timetable API Integration** |
4 | 7 |
|
5 | 8 | An MCP Server that bridges AI agents with the Deutsche Bahn Timetable API, enabling seamless access to German railway schedule data, real-time updates, and station information through a standardized protocol. |
@@ -594,6 +597,93 @@ You can find more EVA numbers using the `GetStationDetails` tool with a station |
594 | 597 |
|
595 | 598 | --- |
596 | 599 |
|
| 600 | +## 🧪 Testing |
| 601 | + |
| 602 | +### Running Tests Locally |
| 603 | + |
| 604 | +The project includes comprehensive unit tests with code coverage tracking. |
| 605 | + |
| 606 | +#### Run All Tests |
| 607 | + |
| 608 | +```bash |
| 609 | +# Navigate to the project directory |
| 610 | +cd DB-TimetableAPI-MCPServer |
| 611 | + |
| 612 | +# Run all tests |
| 613 | +dotnet test |
| 614 | +``` |
| 615 | + |
| 616 | +#### Run Tests with Code Coverage |
| 617 | + |
| 618 | +```bash |
| 619 | +# Run tests and collect coverage data |
| 620 | +dotnet test --collect:"XPlat Code Coverage" --results-directory ./TestResults |
| 621 | + |
| 622 | +# Generate HTML coverage report (requires reportgenerator tool) |
| 623 | +dotnet tool install --global dotnet-reportgenerator-globaltool |
| 624 | +reportgenerator -reports:"TestResults/**/coverage.cobertura.xml" -targetdir:"TestResults/CoverageReport" -reporttypes:"Html;TextSummary" |
| 625 | + |
| 626 | +# View coverage summary |
| 627 | +cat TestResults/CoverageReport/Summary.txt |
| 628 | + |
| 629 | +# Open HTML report in browser |
| 630 | +# The report will be at: TestResults/CoverageReport/index.html |
| 631 | +``` |
| 632 | + |
| 633 | +### Test Structure |
| 634 | + |
| 635 | +The test project (`AbeckDev.DbTimetable.Mcp.Test`) includes: |
| 636 | + |
| 637 | +- **ConfigurationTests.cs**: Tests for configuration model validation |
| 638 | +- **TimeTableServiceTests.cs**: Tests for API service layer with mocked HTTP responses |
| 639 | +- **TimetableToolsTests.cs**: Tests for MCP tool wrappers with error handling |
| 640 | + |
| 641 | +### Coverage Goals |
| 642 | + |
| 643 | +- **Current Coverage**: 78.3% line coverage |
| 644 | +- **Target**: 70%+ line coverage (enforced in CI/CD) |
| 645 | +- **Core Business Logic**: 100% coverage (Services, Tools, Models) |
| 646 | + |
| 647 | +### Testing Guidelines for Contributors |
| 648 | + |
| 649 | +When contributing code, please: |
| 650 | + |
| 651 | +1. **Write Tests**: Add unit tests for any new functionality |
| 652 | +2. **Mock External Dependencies**: Use Moq to mock HTTP clients and external services |
| 653 | +3. **Test Error Scenarios**: Include tests for both success and failure cases |
| 654 | +4. **Maintain Coverage**: Ensure your changes don't drop overall coverage below 70% |
| 655 | +5. **Run Tests Locally**: Verify all tests pass before submitting a PR |
| 656 | + |
| 657 | +Example test pattern: |
| 658 | + |
| 659 | +```csharp |
| 660 | +[Fact] |
| 661 | +public async Task MethodName_WithCondition_ExpectedBehavior() |
| 662 | +{ |
| 663 | + // Arrange |
| 664 | + var mockService = new Mock<ITimeTableService>(); |
| 665 | + mockService.Setup(s => s.MethodAsync(...)).ReturnsAsync(...); |
| 666 | + |
| 667 | + // Act |
| 668 | + var result = await service.MethodAsync(...); |
| 669 | + |
| 670 | + // Assert |
| 671 | + Assert.Equal(expectedValue, result); |
| 672 | +} |
| 673 | +``` |
| 674 | + |
| 675 | +### Continuous Integration |
| 676 | + |
| 677 | +All pull requests automatically run: |
| 678 | +- ✅ Build verification |
| 679 | +- ✅ All unit tests |
| 680 | +- ✅ Code coverage analysis |
| 681 | +- ✅ Coverage threshold checks (70% minimum) |
| 682 | + |
| 683 | +Coverage reports are available as workflow artifacts. |
| 684 | + |
| 685 | +--- |
| 686 | + |
597 | 687 | ## 🤝 Contributing |
598 | 688 |
|
599 | 689 | We welcome contributions from the community! |
|
0 commit comments