- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在测试我自己的 ArrayList 实现时,我在测试之前设置了 MyArrayList 类的实例,为了检查我的逻辑是否在实现的方法中正常工作,我使用了 @FixMethodOrder(MethodSorters.NAME_ASCENDING)。但是,一旦我运行测试,执行的测试的顺序就不是按字典顺序排列的。
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.FixMethodOrder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.runners.MethodSorters;
import java.util.List;
@TestInstance(Lifecycle.PER_CLASS)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public abstract class ListTest {
protected abstract List<Integer> provideList();
private List<Integer> list;
@BeforeAll
public void setUp() {
list = provideList();
for (int i = 0; i < 100; i++) {
list.add(i);
}
}
@Test
public void test1ShouldReturnActualSizeWhenListIsNotEmpty() {
//when
int actual = list.size();
//then
assertEquals(100, actual);
}
@Test
public void test2ShouldReturnFalseWhenListIsNotEmpty() {
//when
boolean actual = list.isEmpty();
//then
assertEquals(false, actual);
}
@Test
public void test3ShouldReturnTrueWhenListContainsElement() {
//when
boolean actual = list.contains(4);
//then
assertEquals(true, actual);
}
@Test
public void test4ShouldReturnFalseWhenListDoesNotContainElement() {
//when
boolean actual = list.contains(200);
//then
assertEquals(false, actual);
}
@Test
public void test5ShouldReturnGivenListAsArray() {
//when
Object[] actual = list.toArray();
Object[] expected = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99};
//then
assertArrayEquals(expected, actual);
}
}
这是我执行的测试的顺序。无论我如何更改测试方法的名称,它始终保持不变:
我哪里搞错了?我还尝试不在这个抽象类上使用注释,而是在从它继承的类上使用注释,但它也没有帮助。
最佳答案
您正在组合 Junit4 和 Junit5。目前Junit5不支持方法顺序:https://github.com/junit-team/junit5/issues/13 .
您只需要使用 Junit4。
关于java - 名称升序 @FixMethodOrder 不适用于 Junit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48068801/
我正在做作业,经过几天的努力,我无法弄清楚为什么在实现归并排序后,我的列表仅包含链接列表中的最后一个对象。它不输出我的整个链表,只输出最后一个对象。如何更改代码以阻止列表在一个对象之后变为 null。
我想对一列进行排序(它是一个带有 Y/N 的标志列)。它应该在每次点击时在升序/降序之间切换。 我的代码不起作用..我是 VBA 新手。请提供任何帮助。 Private Sub CommandButt
我对如何让它正常工作有点困惑。我需要从用户那里获取数字(直到他们输入负数或达到最大大小),并且对于他们添加的每个数字,将其按升序插入到正确的索引中。现在,由于某种原因,即使我定义了常量 10,我的数组
我相当困惑如何创建一个按钮,将打印到 php 文件的表中的数据按升序或降序排序。 "> Order by Week Sort Week 这是我想要实现的一个简单示例,我只是停留在 php
我在使用 C++ 中的 priority_queue 时遇到问题,我有一个优先级队列 vector ,优先级队列包含多个 Person 对象。现在,我希望 priority_queue 根据年龄对 P
我正在使用 Lodash 按列对表中的数据进行排序。当我单击表格列标题中的箭头时,该特定表格列将按升序或降序排序。但是,我希望每一列首先按升序排序,而不管其他列的当前顺序如何。现在,我的函数只根据当前
如果事先知道哪些列可用,则以下代码可以重新排列列,但如果想按降序/升序重新排列列怎么办? StackOverflow 上有一些类似的帖子,但没有一篇可以在事先不知道哪些列可用的情况下这样做。 ty
在 woocommerce 中,我使用以下代码添加了自定义费用: add_action( 'woocommerce_cart_calculate_fees', 'custom_fee_based_on
这可以很好地以最多 1000 个项目的步长对数据进行分页: var q1 = (from book in table.CreateQuery() where book.PartitionKe
您好,我正在使用以下内容对表适配器返回的数据表的结果进行排序 Dim spots = myDataTable.Where(Function(t) t.UserID = 1).OrderByDesce
这可以很好地以最多 1000 个项目的步长对数据进行分页: var q1 = (from book in table.CreateQuery() where book.PartitionKe
我正在尝试获取数据库中最近的 n 个条目的列表,但将它们按升序排序。 显然我可以使用以下方法获取前 n 个条目: SELECT owner_id,message FROM messages WHERE
我尝试使用此方法将数据提取到 mysql 表 $query=$conn->query("SELECT * FROM users ORDER BY id_user ASC"); 这是我的表结构 用户 i
我正在使用 NSFetchedResultsController 在列表中显示对象 Event。 Event 对象具有 startDate 属性和 eventType 属性,它是 CheckIn 类型
我有以下代码/数据: import numpy as np data = np.array([ [12, 1, 0.7, 0], [13, 2, 0.5, 1], [41, 3
所以我是 C++ 的新手,我正在尝试一些初学者练习,这是问题所在:我必须按升序和降序对整数数组进行排序,但每次我尝试按升序排序时,都会出现 0在我的数组中无处替换以前的数组整数。只有当我使用“升序”选
在我的应用程序中,我有一个任务列表(不,它不仅仅是另一个待办事项应用程序),我使用 NSFetchedResultsController 在 UITableView 中显示任务。这是相关的初始化代码:
本人由于项目开发中需要对查询结果list进行排序,这里根据的是每一个对象中的创建时间降序排序。本人讲解不深,只实现目的,如需理解原理还需查阅更深的资料。 1.实现的效果 2.创建排序的对象
ORDER BY _column1, _column2; /* _column1升序,_column2升序 */
我需要插入两个值 num1 = 50和 num2 = 80成一个已按升序排序的数组。我不能使用动态数组或列表。也没有结构或类。这是一个类作业,所以我必须遵循指导方针。教授建议我新建一个数组,newar
我是一名优秀的程序员,十分优秀!