Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should Kotlin test classes be internal?

Tags:

testing

kotlin

When you generate a test class for a given class in IntelliJ, say class Foo, it will generate a test class internal class FooTest. Why does it default to an internal class? What's the advantage of using internal classes for test classes?

The way I was generating test classes is: put cursor on the class name Foo, press Option/Alt+Enter, select "Create Test".

like image 961
z11i Avatar asked Oct 15 '22 07:10

z11i


1 Answers

Using internal visibility means that it can be accessed by other classes in the same module. This is the closest Kotlin has to Java's default 'package-private' which also makes sense for tests written in Java.

Using private is more restrictive making it so that test classes can reuse each other which can be useful some times. There really shouldn't be a use for public test classes, unless they're global test helpers which would be the exception rather than the rule.

like image 134
karmakaze Avatar answered Nov 03 '22 22:11

karmakaze