简体   繁体   English

尽管传递了预期的参数,为什么我仍然面临 junit 5 assertThrows 断言 TimedOutException 的问题?

[英]Why am I facing issue with junit 5 assertThrows for asserting TimedOutException despite passing expected parameters?

I'm trying to assert the TimedOutException using junit 5 assertThrows while clicking a button on page but I'm getting error, may I know the reason?我试图在单击页面上的按钮时使用 junit 5 assertThrows 断言 TimedOutException 但我收到错误,我可以知道原因吗? 在此处输入图像描述

Assert.assertThrows(TimedOutException.class, ()->{homePage.clickQuote();});

clickQuote() method either takes user to next page or throws TimedOutException. clickQuote() 方法要么将用户带到下一页,要么抛出 TimedOutException。

You probably imported and used the wrong class (from JUnit 4 instead of JUnit 5)您可能导入并使用了错误的 class(来自 JUnit 4 而不是 JUnit 5)

In JUnit 5 please use only org.junit.jupiter.api.Assertions instead of org.junit.Assert . In JUnit 5 please use only org.junit.jupiter.api.Assertions instead of org.junit.Assert .

As you mentioned in a comment that you imported org.unit.Assert : This is the utility with the static assertions from JUnit 4, not JUnit 5. It provides a method assertThrows , but with different parameters, and is not upwards compatible with JUnit 5. Usually you expect exceptions in JUnit 4 with the help of annotations. As you mentioned in a comment that you imported org.unit.Assert : This is the utility with the static assertions from JUnit 4, not JUnit 5. It provides a method assertThrows , but with different parameters, and is not upwards compatible with JUnit 5 . 通常你会在注释的帮助下期待 JUnit 4 中的异常。

You can find details on the method parameters in the API docs of JUnit 5.您可以在 JUnit 5 的API 文档中找到有关方法参数的详细信息。

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

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