Onboarding Unit Testing with Mocking Framework for Kruize#1772
Onboarding Unit Testing with Mocking Framework for Kruize#1772pinkygupta-hub wants to merge 12 commits intokruize:mvp_demofrom
Conversation
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Reviewer's GuideIntroduces a Mockito-based JUnit 5 unit test for BulkJobManager’s experiment-name framing logic and modernizes the Maven test stack (JUnit 5 BOM, Mockito, and Surefire) to support ongoing unit testing in the Kruize analyzer module. Sequence diagram for BulkJobManager experiment name unit testsequenceDiagram
actor Developer
participant Maven
participant Surefire
participant JUnit5
participant Mockito
participant BulkJobManagerTest
participant BulkJobManager
participant DataSourceMock
participant WorkloadMetadataMock
participant LabelProviderMock
Developer->>Maven: run mvn clean test
Maven->>Surefire: execute tests
Surefire->>JUnit5: discover and run tests
JUnit5->>BulkJobManagerTest: construct test instance
JUnit5->>Mockito: initialize mocks
Mockito-->>BulkJobManagerTest: inject DataSourceMock, WorkloadMetadataMock, LabelProviderMock
JUnit5->>BulkJobManagerTest: invoke testConstructExperimentNameWithLabels
BulkJobManagerTest->>DataSourceMock: configure experiment data
BulkJobManagerTest->>WorkloadMetadataMock: configure workload metadata
BulkJobManagerTest->>LabelProviderMock: configure labels
BulkJobManagerTest->>BulkJobManager: constructExperimentName(DataSourceMock, WorkloadMetadataMock, LabelProviderMock)
BulkJobManager->>DataSourceMock: getExperimentSource()
DataSourceMock-->>BulkJobManager: experimentSource
BulkJobManager->>WorkloadMetadataMock: getWorkloadName()
WorkloadMetadataMock-->>BulkJobManager: workloadName
BulkJobManager->>LabelProviderMock: getLabelValues()
LabelProviderMock-->>BulkJobManager: labelValues
BulkJobManager-->>BulkJobManagerTest: experimentName
BulkJobManagerTest->>BulkJobManagerTest: assert experimentName
BulkJobManagerTest-->>JUnit5: success
JUnit5-->>Surefire: report test success
Surefire-->>Maven: build success
Maven-->>Developer: tests passed
Class diagram for BulkJobManager unit test with mockingclassDiagram
class BulkJobManager {
+constructExperimentName(DataSource dataSource, WorkloadMetadata workloadMetadata, LabelProvider labelProvider) String
}
class BulkJobManagerTest {
+setUp()
+testConstructExperimentNameWithLabels()
}
class DataSource
class WorkloadMetadata
class LabelProvider
BulkJobManagerTest --> BulkJobManager : tests
BulkJobManager --> DataSource : uses
BulkJobManager --> WorkloadMetadata : uses
BulkJobManager --> LabelProvider : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The tests mutate the static
KruizeDeploymentInfo.experiment_name_formatfield without restoring its original value, which can leak configuration to other tests—consider capturing the original value and resetting it in an@AfterEach(or using a helper) to keep tests isolated. - In
BulkJobManagerMockedTest, some mocks (e.g.,BulkJobStatus jobStatus) appear unused or only minimally exercised; trimming unused mocks or stubbing only whatBulkJobManageractually consumes will keep the test focused and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The tests mutate the static `KruizeDeploymentInfo.experiment_name_format` field without restoring its original value, which can leak configuration to other tests—consider capturing the original value and resetting it in an `@AfterEach` (or using a helper) to keep tests isolated.
- In `BulkJobManagerMockedTest`, some mocks (e.g., `BulkJobStatus jobStatus`) appear unused or only minimally exercised; trimming unused mocks or stubbing only what `BulkJobManager` actually consumes will keep the test focused and easier to maintain.
## Individual Comments
### Comment 1
<location> `pom.xml:293` </location>
<code_context>
+ <include>**/*Test.java</include>
+ </includes>
+ <failIfNoTests>true</failIfNoTests>
+ <argLine>-Dnet.bytebuddy.experimental=true</argLine>
+ </configuration>
</plugin>
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Hardcoding `argLine` may override or conflict with other plugins (e.g., JaCoCo) that also set it.
This will overwrite any `argLine` configured by other plugins (e.g. `jacoco-maven-plugin`), which can disable coverage or other JVM options. Prefer appending to the existing value (e.g. `${argLine} -Dnet.bytebuddy.experimental=true`) or using a composable property (such as `${surefireArgLine}`) instead.
```suggestion
<argLine>${argLine} -Dnet.bytebuddy.experimental=true</argLine>
```
</issue_to_address>
### Comment 2
<location> `pom.xml:289-290` </location>
<code_context>
- <version>2.22.0</version>
+ <version>3.1.2</version>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ <failIfNoTests>true</failIfNoTests>
</code_context>
<issue_to_address>
**question (testing):** The surefire include pattern may unintentionally skip valid tests with other naming conventions.
This change will exclude classes like `*Tests.java`, `*IT.java`, or other existing naming patterns from the test run. If the module uses mixed conventions or contains integration tests, please either broaden the include patterns (e.g., add `**/*Tests.java`, `**/*IT.java`) or rely on surefire’s defaults unless there’s a strong reason to restrict them.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
src/test/java/com/autotune/analyzer/workerimpl/BulkJobManagerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
src/test/java/com/autotune/analyzer/workerimpl/BulkJobManagerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Pinky Gupta <pinky.gupta1@ibm.com>
|
@pinkygupta-hub I see these warnings when I run this, can you take a look at this |
Thanks for pointing this out. These warnings are coming from Mockito/ByteBuddy when running on newer Java versions. They are related to dynamic agent loading and internal APIs, not our implementation, and don’t affect test execution. This is expected behavior and should go away once dependencies are updated to fully support the current JDK. We are already using Mockito 5.8, which is a recent version. |
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <version>5.8.0</version> |
There was a problem hiding this comment.
I see 5.21.0 available, can you update to the latest versions and test it
Description
Onboarding Unit Testing with Mocking Framework for Kruize, added required dependencies in pom and added sample test cases with guidelines.
Fixes # (issue)
Type of change
How has this been tested?
Please describe the tests that were run to verify your changes and steps to reproduce. Please specify any test configuration required.
Test Configuration
Checklist 🎯
Additional information
Include any additional information such as links, test results, screenshots here

Successful test cases, command : mvn clean test
Summary by Sourcery
Introduce a mocking-based unit testing setup for Kruize and configure the build to run JUnit 5 tests reliably.
Build:
Tests: