将ExpectedException与Kotlin一起使用

时间:2015-10-31 06:50:56

标签: java junit 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

1 个答案:

答案 0 :(得分:17)

使用 let backupConfig = Realm.Configuration( path: "\(tmp)/ReadingLog.realm", // This Realm is version 0 readOnly: true ) let backupRealm = try! Realm(configuration: backupConfig) let defaultRealm = try! Realm() // My default Realm is version 1 let books = backupRealm.objects(Book) try! defaultRealm.write { for book in books { defaultRealm.create(Book.self, value: book, update: true) } } 注释例外属性:

@JvmField