JUnit

Test exception

@Rule
public ExpectedException expectedEx = ExpectedException.none();
 
@Test
public void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() {
    expectedEx.expect(RuntimeException.class);
    expectedEx.expectMessage("Employee ID is null");
    expectedEx.expectMessage(CoreMatchers.containsString("ID"));
 
    // do something that should throw the exception...
}

Прочитать текст ошибки в котлине

package io.piano.ai.report.flow

import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException

class TestTest{
    @get:Rule
    var expectedEx: ExpectedException = ExpectedException.none()

    @Test
    fun shouldThrowRuntimeExceptionWhenEmployeeIDisNull() {
        expectedEx.expect(RuntimeException::class.java)
        expectedEx.expectMessage("Employee ID is null")
        // do something that should throw the exception...
        //failure.expectMessage(CoreMatchers.equalTo(...))

        throw java.lang.RuntimeException("1 Employee ID is null 1")
    }

    @Test
    fun name() {
        println("test")
    }
}
Пока не указано иное, содержимое этой страницы распространяется по лицензии Creative Commons Attribution-ShareAlike 3.0 License