java – AssertJ在cause消息上断言
发布时间:2020-12-15 04:35:33 所属栏目:Java 来源:网络整理
导读:有没有办法在使用AssertJ时再次抛出一个方法来检查原因中的消息是否等于某个字符串. 我目前正在做类似的事情: assertThatThrownBy(() - SUT.method()) .isExactlyInstanceOf(IllegalStateException.class) .hasRootCauseExactlyInstanceOf(Exception.class)
有没有办法在使用AssertJ时再次抛出一个方法来检查原因中的消息是否等于某个字符串.
我目前正在做类似的事情: assertThatThrownBy(() -> SUT.method()) .isExactlyInstanceOf(IllegalStateException.class) .hasRootCauseExactlyInstanceOf(Exception.class); 并且想添加一个断言来检查根本原因中的消息. 解决方法
不完全是,目前你能做的最好的就是使用hasStackTraceContaining,例如
Throwable runtime = new RuntimeException("no way",new Exception("you shall not pass")); assertThat(runtime).hasCauseInstanceOf(Exception.class) .hasStackTraceContaining("no way") .hasStackTraceContaining("you shall not pass"); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |