简体   繁体   English

如何使用新的JUnit 4.11功能,包括更改测试名称和设置执行顺序

[英]How to use new JUnit 4.11 features including change test name and set execution order

I am trying to use JUnit 4.11 to set execution order. 我正在尝试使用JUnit 4.11设置执行顺序。

I have tried running the Parameterized test example on this link ( Changing names of parameterized tests ) within Ecipse IDE and I see no change to the displayed test name in Eclipse IDE. 我尝试在Ecipse IDE中的此链接上运行Parameterized测试示例( 更改参数化测试的名称 ),但在Eclipse IDE中看不到显示的测试名称的任何更改。 I expect to see test names displayed like test[1: fib(1)=1] and test[4: fib(4)=3], but instead they are displayed like test[0] and test[1] 我希望看到测试名称显示为test [1:fib(1)= 1]和test [4:fib(4)= 3],但是它们却像test [0]和test [1]一样显示

@FixMethodOrder(MethodSorters.NAME_ASCENDING)

The following example running in Eclipse IDE results in the following execution order (b,a,d,c) instead of the expected (a,b,c,d) 在Eclipse IDE中运行的以下示例导致以下执行顺序(b,a,d,c),而不是预期的执行顺序(a,b,c,d)

package com.org;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ExecutionOrderTestName {

    @Test
    public void bTest() {
        System.out.println("b");
    }

    @Test
    public void aTest() {
        System.out.println("a");
    }

    @Test
    public void dTest() {
        System.out.println("d");
    }

    @Test
    public void cTest() {
        System.out.println("c");
    }
}

The ordering of tests is not happening, what am I doing wrong? 测试的顺序未发生,我在做什么错?

This sounds like you have another JUnit on the classpath. 听起来您在类路径上还有另一个JUnit。 See if you have, and remove it. 看看是否有,然后将其删除。 In Eclipse, you can look at Project Properties-> Java Build Path, then the Libraries tab. 在Eclipse中,您可以查看Project Properties-> Java Build Path,然后查看Libraries选项卡。

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

相关问题 如何在 JUnit5 中为测试套件设置自定义测试执行顺序? - How to set custom test execution order for a test suite in JUnit5? JUnit 4 按照在 class 中的编程顺序执行测试 - JUnit 4 Test Execution in the order how they are programmed in class 如何使用 Junit 4.11 有条件地执行测试类 - How to execute test classes conditionally using Junit 4.11 Java中的参数化jUnit测试:将jUnit 4.11中的“自定义测试名称”功能(@Parameters(name =“ namestring”))与junitparams @FileParameter结合起来吗? - Parameterized jUnit tests in Java: Combine 'custom test name' feature (@Parameters(name=“namestring”)) in jUnit 4.11 with junitparams @FileParameter? 如何为junit测试设置测试名称-但不使用测试方法的名称? - How to set test name for junit test - but not using name of test method? 如何在 Junit5 / spring 引导中命令执行 controller 测试类? - How to order execution of controller test classes in Junit5 / spring boot? 从Ant到Gradle:JUnit(4.11)测试转换 - Ant to Gradle: JUnit (4.11) Test conversion JUnit 4.11在@After中获取测试结果 - JUnit 4.11 get test result in @After 如何在Allure中更改测试步骤的执行顺序 - How to change the order of execution of test steps in Allure Junit 4执行命令vs Junit 5 - Junit 4 execution order vs Junit 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM