Skip to content

Add comprehensive test coverage and automated coverage reporting#96

Merged
gimlet2 merged 8 commits intomainfrom
copilot/add-test-coverage-reports
Oct 29, 2025
Merged

Add comprehensive test coverage and automated coverage reporting#96
gimlet2 merged 8 commits intomainfrom
copilot/add-test-coverage-reports

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

ROADMAP identified minimal test coverage as a critical gap. Added unit and integration tests and integrated JaCoCo coverage reporting into CI/CD pipeline with automated PR comments and badges.

Changes

Test Coverage

  • Added 42 unit tests across all core components (Server, HttpRequest, HttpResponse, ClientThread, HttpMethod, Status)
  • Added 10 integration tests that start actual Server instances and make HTTP requests using HttpURLConnection
  • Achieved 87% instruction coverage, 62% branch coverage (up from 0%)
  • Exceeded ROADMAP's 80% coverage target

Server Lifecycle Management

  • Added shutdown() method to Server class for proper lifecycle management
  • Encapsulates thread pool shutdown logic in a clean public API
  • Integration tests use the new shutdown method for proper cleanup

Integration Tests

  • Tests verify real HTTP communication with GET, POST, PUT, DELETE requests
  • Tests cover 404 error handling, regex routing, filters, and exception handlers
  • Each test runs on a unique port to avoid conflicts
  • Proper server lifecycle management with cleanup after each test using server.shutdown()
  • Optimized test utilities: Replaced Thread.sleep with socket-based server readiness checks
  • Extracted common HTTP request logic into makeHttpRequest() utility function
  • Tests run ~3.5x faster (2 seconds vs 7 seconds) with improved reliability

Coverage Infrastructure

  • Added JaCoCo Maven plugin (v0.8.12) to generate HTML/XML/CSV reports
  • Coverage reports uploaded as workflow artifacts

GitHub Workflow Enhancements

  • Coverage reports auto-posted as PR comments via madrapps/jacoco-report@v1.6.1
  • Coverage badges auto-generated and committed to .github/badges/ on main branch pushes
  • Enforced 60% minimum coverage threshold for PRs
  • Fixed glob pattern quoting for safer bash scripting

README Updates

  • Added coverage and branch coverage badges

Example Unit Test

@Test
fun testGetRouteReturnsResponse() {
    val server = Server()
    server.get("/hello") { _, res -> res.send("Hello World") }
    
    val request = HttpRequest(HttpMethod.GET, "/hello", "HTTP/1.1", emptyMap(), reader)
    val response = HttpResponse(stream = stream)
    
    server.bindings[HttpMethod.GET]?.get("/hello")?.invoke(request, response)
    
    assertTrue(stream.toString().contains("Hello World"))
}

Example Integration Test

@Test
fun testGetRequest() {
    val testPort = getNextPort()
    server = Server(testPort)
    
    server!!.get("/test") { _, _ -> "Hello from GET" }
    server!!.start(testPort)
    
    waitForServerToStart(testPort)
    
    val (responseCode, responseBody) = makeHttpRequest(testPort, "/test")
    
    assertEquals(200, responseCode)
    assertTrue(responseBody.contains("Hello from GET"))
}

All 52 tests passing with 87% instruction coverage and 62% branch coverage.

Original prompt

in the ROADMAP you've mentioned low test coverage. add all missing test and and coverage report into workflow. can we have a badge with it? I like coverage report to be included as a comment into each PR after the build


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits October 29, 2025 20:25
Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
Copy link
Owner

@gimlet2 gimlet2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I would like to see also an integration tests that run Server instance and make http requests to it with http client and accerting results. please add it

Copilot AI changed the title [WIP] Add missing tests and coverage report to workflow Add comprehensive test coverage and automated coverage reporting Oct 29, 2025
Copilot AI requested a review from gimlet2 October 29, 2025 20:33
Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 29, 2025

@copilot I would like to see also an integration tests that run Server instance and make http requests to it with http client and accerting results. please add it

Added integration tests in commit f38d294. The tests start a Server instance on unique ports and make real HTTP requests using HttpURLConnection.

10 integration tests added:

  • GET, POST, PUT, DELETE requests
  • 404 not found handling
  • Regex routing (/do/.*/smth)
  • Before/after filters
  • Exception handlers
  • Multiple routes

All 51 tests (41 unit + 10 integration) are passing. Coverage improved from 63% to 87% instruction coverage and 62% branch coverage, exceeding the 80% ROADMAP target.

@gimlet2 gimlet2 requested a review from Copilot October 29, 2025 20:43
@gimlet2 gimlet2 marked this pull request as ready for review October 29, 2025 20:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive test coverage and code quality tooling to the kottpd project. The changes introduce JaCoCo for code coverage reporting, CI/CD workflow enhancements for coverage tracking, and extensive unit and integration tests for all major framework components.

  • Adds JaCoCo coverage reporting with Maven plugin configuration
  • Introduces comprehensive test suites for all core classes (Server, HttpRequest, HttpResponse, Status, HttpMethod, ClientThread)
  • Enhances CI/CD with coverage badges, PR comments, and artifact uploads

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pom.xml Adds JaCoCo Maven plugin configuration for code coverage reporting
.github/workflows/build.yml Enhances build workflow with coverage generation, badge creation, and PR comment integration
src/test/kotlin/.../StatusTest.kt Adds unit tests for HTTP status code enums
src/test/kotlin/.../ServerTest.kt Adds unit tests for server configuration, routing, and filters
src/test/kotlin/.../ServerIntegrationTest.kt Adds integration tests for end-to-end HTTP request/response scenarios
src/test/kotlin/.../HttpResponseTest.kt Adds unit tests for HTTP response handling
src/test/kotlin/.../HttpRequestTest.kt Adds unit tests for HTTP request parsing and content handling
src/test/kotlin/.../HttpMethodTest.kt Adds unit tests for HTTP method enum values
src/test/kotlin/.../ClientThreadTest.kt Adds unit tests for client thread request reading
README.md Adds coverage badges to project documentation
.github/badges/jacoco.svg Coverage badge SVG file
.github/badges/branches.svg Branch coverage badge SVG file

@github-actions
Copy link

github-actions bot commented Oct 29, 2025

Code Coverage Report

Overall Project 87.5% 🍏
Files changed 100% 🍏

File Coverage
Server.kt 75.83% 🍏

gimlet2 and others added 2 commits October 29, 2025 21:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
…tions

Co-authored-by: gimlet2 <758568+gimlet2@users.noreply.github.com>
@gimlet2 gimlet2 merged commit 8a02156 into main Oct 29, 2025
2 checks passed
@gimlet2 gimlet2 deleted the copilot/add-test-coverage-reports branch October 29, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants