如何使 JUnit 测试用例按顺序运行?

How to make JUnit test cases to run in sequential order?(如何使 JUnit 测试用例按顺序运行?)
本文介绍了如何使 JUnit 测试用例按顺序运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 JUnit4.

I am using JUnit4.

我在一个测试用例中有一套测试方法.

I have a set of test methods in a test case.

每个测试方法插入一些记录并验证一个测试结果,最后删除插入的记录.

Each test method inserts some records and verify a test result and finally delete the records inserted.

由于 JUnit 并行运行,测试方法会因为某些原因而失败以前的测试方法执行期间存在的记录.这只发生在我同事的机器上(Windows 7),不在我的机器上(Cent操作系统 6).

Since the JUnit run in parallel, test methods fail because of some records present during the execution of previous test method. This happen only in my colleague machine(Windows 7), not in my machine(Cent OS 6).

我们需要的是测试方法必须在我们所有的机器中通过.

What we need is that the test methods have to pass in all our machines.

我已尝试清除 Setup() 方法中的记录,但它再次仅适用于我的机器.JUnit 中是否有任何选项可以使测试方法以统一的顺序运行?

I have tried clearing the records in the Setup() method but again it works only on my machine. Is there any option available in JUnit to make the test methods to run in a uniform sequential order ?

谢谢,

推荐答案

JUnit 4.11 现在支持使用 @FixMethodOrder 注解.

JUnit 4.11 now supports specifying execution order using @FixMethodOrder annotation.

这篇关于如何使 JUnit 测试用例按顺序运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)