OpenEMS Java Test Skill
Use this skill when writing or fixing Java Edge/Backend tests.
Test Scope
- Test the use case and its observable behavior, not every method, branch, or implementation detail.
- Prefer the highest practical component-level entry point.
- Do not test private methods or small internal helpers directly.
- Cover the reported behavior together with meaningful boundaries.
- Do not add unrelated robustness scenarios unless they are explicitly requested.
- One test should normally represent one use case or behavioral rule.
- Multiple assertions are fine when they describe one use-case result.
Before implementing, briefly summarize the planned test cases.
Ask the developer only when:
- the expected behavior or scope is unclear
- additional edge cases would broaden the requested scope
- a JUnit 4 test class could be migrated to JUnit Jupiter
For small and clear changes, continue without waiting for confirmation.
Existing Tests and Parameterization
- Inspect existing tests before adding new ones.
- Extend an existing test when it already covers the same use case.
- Avoid duplicate coverage.
- Prefer parameterized tests when cases use the same setup and assertions and differ only in input and expected output.
- Keep separate tests when cases represent different behavior or would be harder to understand when parameterized.
Framework Choice
- Prefer JUnit Jupiter using the version already configured in the repository.
- Never mix JUnit 4 and Jupiter within one test class.
- For new test classes, use JUnit Jupiter unless a technical constraint requires JUnit 4.
- When modifying a small JUnit 4 class, ask whether the complete class should be migrated to Jupiter.
- Recommend migration when it is low-risk and mainly requires changing imports, annotations, assertions, or straightforward parameterized tests.
- Keep JUnit 4 when custom runners, complex rules, runtime constraints, or a large migration make it risky or out of scope.
- Do not add unnecessary test dependencies.
OpenEMS Test Patterns
- Prefer existing OpenEMS test infrastructure over custom fixtures or test harnesses.
- Use
ComponentTest, TestCase, channel assertions, and existing component mocks where applicable.
- Build configs through existing builders such as
MyConfig.create().setId("id0").build().
- Preserve intentional trailing
// in fluent test chains.
- Avoid custom helper methods unless they clearly improve readability.
- Prefer a little duplication over abstractions that hide setup, inputs, execution, or expected behavior.
- Keep tests deterministic and close to the changed behavior.
- Avoid starting a full OSGi runtime unless the existing test style requires it.
Controller Test Focus
For controller tests, consider only aspects relevant to the requested use case:
- scheduler and controller-order effects
- ESS, grid, PV, and load sign conventions
- relevant channel values and states
- meaningful min/max boundaries
- configuration activation or updates
- resulting channels, set-points, or power behavior
Do not automatically create tests for every item in this list.
Validation
Use the Gradle wrapper and the narrowest relevant task.
On Windows PowerShell:
.\gradlew.bat :bundle.name:test
.\gradlew.bat :bundle.name:checkstyleTest
1---2name: oe-junit3description: Use when writing or fixing Java tests in the OpenEMS OSGi/bnd workspace, including JUnit 4 and JUnit Jupiter tests.4---56# OpenEMS Java Test Skill78Use this skill when writing or fixing Java Edge/Backend tests.910## Test Scope1112- Test the use case and its observable behavior, not every method, branch, or implementation detail.13- Prefer the highest practical component-level entry point.14- Do not test private methods or small internal helpers directly.15- Cover the reported behavior together with meaningful boundaries.16- Do not add unrelated robustness scenarios unless they are explicitly requested.17- One test should normally represent one use case or behavioral rule.18- Multiple assertions are fine when they describe one use-case result.1920Before implementing, briefly summarize the planned test cases.2122Ask the developer only when:2324- the expected behavior or scope is unclear25- additional edge cases would broaden the requested scope26- a JUnit 4 test class could be migrated to JUnit Jupiter2728For small and clear changes, continue without waiting for confirmation.2930## Existing Tests and Parameterization3132- Inspect existing tests before adding new ones.33- Extend an existing test when it already covers the same use case.34- Avoid duplicate coverage.35- Prefer parameterized tests when cases use the same setup and assertions and differ only in input and expected output.36- Keep separate tests when cases represent different behavior or would be harder to understand when parameterized.3738## Framework Choice3940- Prefer JUnit Jupiter using the version already configured in the repository.41- Never mix JUnit 4 and Jupiter within one test class.42- For new test classes, use JUnit Jupiter unless a technical constraint requires JUnit 4.43- When modifying a small JUnit 4 class, ask whether the complete class should be migrated to Jupiter.44- Recommend migration when it is low-risk and mainly requires changing imports, annotations, assertions, or straightforward parameterized tests.45- Keep JUnit 4 when custom runners, complex rules, runtime constraints, or a large migration make it risky or out of scope.46- Do not add unnecessary test dependencies.4748## OpenEMS Test Patterns4950- Prefer existing OpenEMS test infrastructure over custom fixtures or test harnesses.51- Use `ComponentTest`, `TestCase`, channel assertions, and existing component mocks where applicable.52- Build configs through existing builders such as `MyConfig.create().setId("id0").build()`.53- Preserve intentional trailing `//` in fluent test chains.54- Avoid custom helper methods unless they clearly improve readability.55- Prefer a little duplication over abstractions that hide setup, inputs, execution, or expected behavior.56- Keep tests deterministic and close to the changed behavior.57- Avoid starting a full OSGi runtime unless the existing test style requires it.5859## Controller Test Focus6061For controller tests, consider only aspects relevant to the requested use case:6263- scheduler and controller-order effects64- ESS, grid, PV, and load sign conventions65- relevant channel values and states66- meaningful min/max boundaries67- configuration activation or updates68- resulting channels, set-points, or power behavior6970Do not automatically create tests for every item in this list.7172## Validation7374Use the Gradle wrapper and the narrowest relevant task.7576On Windows PowerShell:7778```powershell79.\gradlew.bat :bundle.name:test80.\gradlew.bat :bundle.name:checkstyleTest81```