In Java, il programmatore può specificare previsto eccezioni per i casi di test JUnit come questo:prova eccezioni previste nel Kotlin
@Test(expected = ArithmeticException.class)
public void omg()
{
int blackHole = 1/0;
}
Come dovrei fare questo in Kotlin? Ho provato due varianti di sintassi, ma nessuno di loro ha lavorato:
import org.junit.Test as test
// ...
test(expected = ArithmeticException) fun omg()
Please specify constructor invocation;
classifier 'ArithmeticException' does not have a companion object
test(expected = ArithmeticException.class) fun omg()
name expected^
^expected ')'
'JavaClass()' è deprecato ora. Utilizzare invece 'MyException :: class.java'. –
user2138356
failWith è deprecato, [assertFailsWith] (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.test/assert-fails-with.html) dovrebbe invece essere usato. – gvlasov