Skip to content

Improve backend test coverage, add CI workflow, and introduce testable design with mocking#5909

Open
TwilightVoyager777 wants to merge 38 commits intoStirling-Tools:mainfrom
TwilightVoyager777:main
Open

Improve backend test coverage, add CI workflow, and introduce testable design with mocking#5909
TwilightVoyager777 wants to merge 38 commits intoStirling-Tools:mainfrom
TwilightVoyager777:main

Conversation

@TwilightVoyager777
Copy link

Description of Changes

What was changed

This pull request improves the testing infrastructure and testability of the Stirling-PDF backend.

Key changes include:

  • Added multiple unit tests and white-box tests for backend components such as:

    • RotationController
    • SecretMasker
    • GlobalExceptionHandler
    • MobileScannerController
    • LanguageService
  • Extended existing tests to cover edge cases and boundary conditions (e.g., rotation angles and validation logic).

  • Implemented FSM-based testing to improve coverage for certain features.

  • Introduced mocking and stubbing techniques to isolate dependencies and improve test reliability.

  • Added helper methods and small refactors to support testable design.

  • Added a GitHub Actions CI workflow to automatically build the backend and run core tests.

  • Cleaned up CI configuration by removing unused workflows.

  • Minor fixes and improvements including Gradle updates and small bug fixes discovered during testing.

Why the change was made

These changes were made to improve the test coverage, reliability, and maintainability of the backend system.

The work applies several software testing practices including:

  • White-box testing
  • FSM-based testing
  • Mocking and stubbing
  • Continuous Integration (CI)

By adding automated tests and CI validation, the project can detect regressions earlier and ensure that important backend components behave correctly.

Challenges encountered

  • Some components were originally tightly coupled, which made them difficult to test directly.
  • Mocking certain dependencies required careful configuration to avoid unintended side effects.
  • Configuring the CI workflow to run only the necessary backend tests required adjustments to the workflow setup.

Checklist

General

Documentation

Translations (if applicable)

UI Changes (if applicable)

  • Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR)

Testing (if applicable)

TwilightVoyager777 and others added 30 commits January 29, 2026 15:14
Extend RotationController tests to cover partition boundaries (0°) and negative angles, ensuring valid multiples of 90 succeed; update report with partitioning details.
Add SecretMasker tests(no side effects + false positives)
Feature B: FSM coverage tests for SecretMasker
Add white-box tests for GlobalExceptionHandler
CI: add targeted tests for GlobalExceptionHandler and SecretMasker
Add MobileScannerController validation helper and tests (mocking + te…
Remove unused GitHub Actions workflows (keep course-part4-ci.yml only)
@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines ignoring generated files. label Mar 10, 2026
@stirlingbot stirlingbot bot added Java Pull requests that update Java code Back End Issues related to back-end development Docker Pull requests that update Docker code Security Security-related issues or pull requests API API-related issues or pull requests Test Testing-related issues or pull requests Github Devtools Development tools Gradle Pull requests that update Gradle code labels Mar 10, 2026
@Frooodle
Copy link
Member

Appreciate all the testing however you have made several changes to our GHAs which should not be done, please revert all GHA changes

Thanks again for the added test cases though! Certainly something we need more of

@Frooodle
Copy link
Member

Once these have been restored will review more

@TwilightVoyager777
Copy link
Author

sure I will do that soon

Copy link
Collaborator

@balazs-szucs balazs-szucs left a comment

Choose a reason for hiding this comment

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

Hi,

thanks for the PR left some comments for you.

Comment on lines 71 to 79
Copy link
Collaborator

@balazs-szucs balazs-szucs Mar 10, 2026

Choose a reason for hiding this comment

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

So, this has caused many headaches in the past, I believe we prefer not to cache via gradle. Frooodle is working some docker caching parrallel to this I believe

Comment on lines 156 to 164
Copy link
Collaborator

Choose a reason for hiding this comment

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

SAme comment as above

Comment on lines 24 to 25
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unnecesary (?)

id "org.springdoc.openapi-gradle-plugin" version "1.9.0"
id "io.swagger.swaggerhub" version "1.3.2"
id "com.diffplug.spotless" version "8.1.0"
id "com.github.jk1.dependency-license-report" version "3.0.1"
id "com.github.spotbugs" version "6.1.7" apply false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +322 to +334
spotbugs {
ignoreFailures = true
effort = "max"
reportLevel = "low"
}

tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
reports {
xml.required.set(true)
html.required.set(true)
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you test this and add some hints, how this supposed to work?

Comment on lines +61 to +62
// title is set both as ProblemDetail.title and property "title"
assertEquals(pd.getTitle(), pd.getProperties().get("title"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is asserting (potentially) non-RFC complaint behaviour I believe, though I'll do some reasearching.

My intuition is that the ProblemDetail.title and property "title" shouldn't be both set. It's duplication


import jakarta.servlet.http.HttpServletRequest;

class GlobalExceptionHandlerTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this quite light or? We obviously didn't have testing for this before the PR, but this can be great place to make more tests.

@@ -58,6 +62,62 @@ public void testRotatePDF() throws IOException {
assertEquals(200, response.getStatusCode().value());
}

@Test
public void testRotatePDFZeroAngle() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is confusing.

Better test would be to: testRotatePDF_ShouldMaintainExistingRotation_WhenAngleIsZero

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if we already here maybe bump to node 24? That is the latest, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API API-related issues or pull requests Back End Issues related to back-end development Devtools Development tools Docker Pull requests that update Docker code Github Gradle Pull requests that update Gradle code Java Pull requests that update Java code Security Security-related issues or pull requests size:XXL This PR changes 1000+ lines ignoring generated files. Test Testing-related issues or pull requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants