繁体   English   中英

Junit5:等价于@Rule 和 Expect

[英]Junit5: Equivalent of @Rule and Expect

我有一些我用旧版本的 jUnit 编写的代码。 现在我正在尝试迁移。

如何在 Junit5 中编写这个?

 @Test
  public void testSignatureFailureRuntimeException() throws Exception {
    thrown.expect(java.lang.IllegalArgumentException.class);
    HmacUtil hmacUtil = new HmacUtil(HmacUtil.SignatureAlgorithm.HMAC_SHA1, "");
  }

另一个是@Rule


@ExtendWith(VertxExtension.class)
public class FunctionDeploymentInfoTest {

  @Rule
  public ExpectedException thrown = ExpectedException.none();

使用第一个,您可以尝试:

    Assertions.assertThrows(IllegalArgumentException.class, () -> new HmacUtil(HmacUtil.SignatureAlgorithm.HMAC_SHA1, ""));

使用第二个可能会对您有所帮助: How to replace WireMock @Rule annotation in JUnit 5?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM