koog icon indicating copy to clipboard operation
koog copied to clipboard

Refactor Prompt Tests

Open kpavlov opened this issue 6 months ago • 1 comments

Changes Made

  • Created a new abstract base class AbstractPromptTest that contains shared test fields, constants, and data providers
  • Extracted serialization-specific tests into a new PromptSerializationTest class
  • Updated the original PromptTest class to contain only non-serialization tests
  • Both test classes now extend the abstract base class to reuse common test infrastructure
  • Replaced all JUnit assertions (assertEquals, assertTrue, assertNull) with their Kotest equivalents (shouldBe, shouldBeTrue, shouldBeNull) for improved readability
  • Added shouldBeEqualToComparingFields for serialization tests to make sure all fields are verified. Remove unnecessary explicit assertions.
  • Implemented assertSoftly(subject) { ... } for multiple assertions on the same subject
  • Added withClue for non-obvious assertions to provide better context for failures

Motivation

This refactoring improves the test organization by:

  • Separating concerns: Serialization tests are now isolated from other prompt functionality tests
  • Reducing code duplication: Common test setup and data providers are now in a shared abstract class
  • Improving maintainability: Each test class has a clear, focused responsibility
  • Making tests more readable: Smaller, more focused test classes are easier to understand
  • Enhancing test failure messages: Kotest assertions provide more informative error messages
  • Grouping related assertions: Using assertSoftly to see all failures at once rather than stopping at the first failure

Type of the change

  • [ ] New feature
  • [ ] Bug fix
  • [ ] Documentation fix
  • [x] Tests improvement

Checklist for all pull requests

  • [x] The pull request has a description of the proposed change
  • [x] I read the Contributing Guidelines before opening the pull request
  • [x] The pull request uses develop as the base branch
  • [ ] Tests for the changes have been added
  • [x] All new and existing tests passed
Additional steps for pull requests adding a new feature
  • [ ] An issue describing the proposed change exists
  • [ ] The pull request includes a link to the issue
  • [ ] The change was discussed and approved in the issue
  • [ ] Docs have been added / updated

kpavlov avatar Jul 12 '25 08:07 kpavlov

Updated the original PromptTest class to contain only non-serialization tests

Was it reverted? I don't see it in the changelist.

skarpovdev avatar Aug 07 '25 13:08 skarpovdev