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".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With