在 Kotlin 中使用 ExpectedException

Use ExpectedException with Kotlin

我已经声明了 Kotlin 的预期异常:

@Rule
public var exception = ExpectedException.none()

现在我的集成测试用例:

@Test
@Transactional
fun authorize_withInvalidToken()
{
    val response = controller.authorize(networkType = "facebook", oauthToken = "", oauthTokenSecret = null)
    exception.expect(UnauthorizedException::class.java)

}

我收到错误:

org.junit.internal.runners.rules.ValidationError: The @Rule 'exception' must be public.

有办法解决这个问题吗?现在我只使用手动 try/catch/assert

@JvmField注释异常属性:

@Rule
@JvmField
var exception = ExpectedException.none()