我写了一些代码来打印出“设置”字样,然后运行测试然后打印出“关闭测试”。但Selenium正在跳过我的[Before]和[After]方法,只能自己运行测试。
connecting to: mongodb://127.0.0.1:27017
W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed
出于某种原因,它只打印出来自@Test方法的“运行测试”并且它正在跳过我的Before和After方法。我尝试重新编写代码,并重新启动eclipse。但到目前为止没有任何帮助。以下是控制台日志的屏幕截图。
答案 0 :(得分:2)
主要问题是您混淆了JUnit 4.x
注释和JUnit 5.x
注释。
JUnit 4.x
的基本注释如下:
@BeforeClass
强> @AfterClass
强> @Before
强> @After
强> @Test
强> 您已通过 @Before
和分别解析了 @After
和 import org.junit.Before;
注释import org.junit.After;
强>
但您通过 @Test
import org.junit.jupiter.api.Test;
JUnit 5.x
删除 Project Workspace
外部广告罐的引用。@Test
解析 import org.junit.Test
注释。Clean
Project Workspace
通过您的IDE
。Execute
您的 Tests
。