[英]How do I specificy the order of execution for methods in my testing?
I have a .java file called myTest.java and inside of it I have two test methods (in this order created) called: 我有一个名为myTest.java的.java文件,在其中有两个测试方法(按创建顺序):
public void testGrabSubdevicedata(){
// do something and assert
}
public void testSubdevice(){
// do something again and assert
}
For some reason it executes the "testSubdevice()" method first, and so there must be some sort of alphabetical method execution set. 由于某种原因,它首先执行“ testSubdevice()”方法,因此必须存在某种按字母顺序排列的方法执行集。 How do I turn this off so it executes in the order I placed it it?
如何关闭此功能,使其按我放置的顺序执行?
EDIT: 编辑:
This is with Eclipse Jee Neon and Maven plugin. 这是与Eclipse Jee Neon和Maven插件一起使用的。
You can use 您可以使用
import org.junit.FixMethodOrder;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class WhateverTest {
This will guarantee you that JUnit runs your test in that specific order. 这将确保您JUnit以该特定顺序运行测试。 There aren't too many such orders;
这样的命令没有太多; but probably one that fits your needs.
但可能符合您的需求。
But a word of warning: this is bad practice! 但是请注意:这是不好的做法! Fixing execution order is something that you should only do when you have very good reasons to do so.
只有在有充分理由时,才应该确定执行顺序。
Finally: read about java naming style guides. 最后:阅读有关Java命名样式指南的信息。 Class names start UpperCase;
类名以UpperCase开头; always;
总是; even for tests.
即使是测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.