我有一个像这样的 InstrumentedTest 类:
@RunWith(AndroidJUnit4::class)
class MyInstrumentedTest {
@Inject
private lateinit var myVar:MyType
@BeforeClass
fun method(){
with(myVar){
...
Run Code Online (Sandbox Code Playgroud)
这会产生错误,因为method必须是静态的。如果我将 @BeforeClass 方法放入伴生对象中并使用 @JvmStatic 进行注释,则无法使用注入的 myVar。在一般情况下和在这种情况下,是否有更合适的方法使用 kotlin 使用 @BeforeClass ?