Kotlin: Make an internal function visible to unit tests

If the tests are in a different module than the production code (which is common), what is the best way to make internal functions visible to the tests?

In Java, I will have production code and test in the same package and make the package-private methods to be tested (plus add annotation @VisibleForTestif this is the only reason, private rather than private test). Unfortunately, Kotlin does not have a private-package concept.

+11
source share
2 answers

Classes and methods marked with an access modifier internalwill work from the current versions of Kotlin, Gradle, as well as Intellij to access these methods from test classes. The tools consider the main and test source paths as part of the same module.

Have you tried this before? And if this fails, you should report an error, as it has already been reported, fixed and should be in order in any current version.

+9
source

Probably the easiest solution is to place your unit tests depending on the internal code in the same module with the production code and leave only integration tests that use the open API in a separate module.

, internal .

+6

Source: https://habr.com/ru/post/1681106/


All Articles