Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception 如何在运行时捕获java断言错误_Exception_Junit_Runtime Error_Assert_Assertion - Fatal编程技术网

Exception 如何在运行时捕获java断言错误

Exception 如何在运行时捕获java断言错误,exception,junit,runtime-error,assert,assertion,Exception,Junit,Runtime Error,Assert,Assertion,前提条件:VM参数-ea已启用 源代码中的示例: assert booleanVariable; 如果booleanVariable为false,将抛出AssertionError 我编写了JUnit测试,它会导致错误的booleanVariable,因此如何在不使用插件的情况下捕获错误而不是停止JUnit测试。请注意,该应用程序的功能相当于一个线程模块。因此,JUnit测试调用一个通用的postMessage方法,如下所示: @Test public void myTest(){

前提条件:VM参数-ea已启用

源代码中的示例:

assert booleanVariable;
如果booleanVariable为false,将抛出AssertionError

我编写了JUnit测试,它会导致错误的booleanVariable,因此如何在不使用插件的情况下捕获错误而不是停止JUnit测试。请注意,该应用程序的功能相当于一个线程模块。因此,JUnit测试调用一个通用的postMessage方法,如下所示:

@Test
    public void myTest(){
        Message invalidMessage = new Message("I am invalid");
        //somewhere in threadedModule source code would throw AssertionError 
        //after reading from its inputQueue
        threadedModule.postMessage(invalidMessage );
        assertNotNull(onputQueue.waitForNextMessage(timeOutTime,timeOutMessage));
}

谢谢大家!

这是无法实现的,因为您创建的线程模块运行在与JUnit测试线程分离的线程上。try-catch块只能在其自己的线程内捕获throwable