使用junit4管理线程

发布于 2024-09-19 04:10:32 字数 500 浏览 6 评论 0原文

使用 Junit4,我尝试编写一个包含 3 个 @test 的测试(.class),并且需要在每个测试中打开应用程序。

因此,在启动应用程序并关闭它的 init 函数中:

@BeforeClass
public static void setupOnce() {
    final Thread thread = new Thread() {
        public void run() {
            //start the appli in the main
            thread.start();
        }
    }
}

@AfterClass
public static void CloseAppli() {
    closeAppli();
}

在我的 testClass 中: TestButtons.java 我想在每个 @test 中启动应用程序,这是不可能的......

有什么想法吗?

With Junit4, I tried to write a test (.class) that contains 3 @test and need to open the app in each test.

So in the function init that start the app and close it:

@BeforeClass
public static void setupOnce() {
    final Thread thread = new Thread() {
        public void run() {
            //start the appli in the main
            thread.start();
        }
    }
}

@AfterClass
public static void CloseAppli() {
    closeAppli();
}

In my testClass: TestButtons.java I want to start the appli in each @test which is not possible...

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听风念你 2024-09-26 04:10:32

看来您正在寻找的是 @After 方法。这是在每次单独测试后调用的。 @AfterClass 仅在所有测试结束时调用一次。

http://junit.sourceforge.net/javadoc/org/junit/After.html

It seems what you're looking for is the @After method. That's called after every individual test. @AfterClass is only called once at the ending of ALL the tests.

http://junit.sourceforge.net/javadoc/org/junit/After.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文