我是java的新手。我正在研究我的学校项目,我遇到了这个错误信息。
Class not found: ""Empty test suite.
之前我做过这样的测试,但他们一直在努力。
我没有写所有的方法。我试图先运行该文件。我已经找到了解决办法,但没有一个能适合我的情况。
这是我的测试代码:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestLab06 {
@Test
public void testIntListInsert() {
int[] arr = {1, 3, 5};
IntList test1 = new IntList(arr);
IntList test2 = new IntList();
test1.insert(2, 1);
test1.insert(4, 3);
assertEquals(5, test1.getSize());
assertEquals(3, test1.get(2));
assertEquals(4, test1.get(3));
test2.insert(1, 1);
assertEquals(1, test2.get(0));
assertEquals(1, test2.getSize());
test2.insert(10, 10);
assertEquals(10, test2.get(1));
}
@Test
public void testIntListMerge() {
int[] arr = {1, 3, 5};
IntList test1 = new IntList(arr);
int[] arr2 = {2, 4, 6, 8};
IntList test2 = new IntList(arr2);
IntList test = IntList.merge(test1, test2);
int[] expected ={1, 2, 3, 4, 5, 6, 8};
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], test.get(i));
}
}
@Test
public void testIntListReverse() {
int[] arr = {1, 2, 3, 4, 5, 6, 8};
IntList test1 = new IntList(arr);
test1.reverse();
int[] expected = {8, 6, 5, 4, 3, 2, 1};
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], test1.get(i));
}
}
@Test
public void testDLLInsertRemove() {
DLList l = new DLList();
l.insertBack(2);
l.insertFront(1);
assertEquals(1, l.get(0));
l.insert(4, 1);
assertEquals(4, l.get(1));
l.insert(1, 10);
// List is 1, 4, 2, 1
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
l.remove(1);
assertEquals(2, l.size);
l.remove(l.sentinel.next);
assertEquals(1, l.size);
assertEquals(2, l.sentinel.next.item);
}
@Test
public void testDLLDoubleReverse() {
DLList l = new DLList();
l.insertBack(4);
l.insertBack(2);
l.doubleInPlace();
assertEquals(4, l.size);
assertEquals(4, l.get(0));
assertEquals(4, l.get(1));
assertEquals(2, l.get(2));
assertEquals(2, l.get(3));
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
l.reverse();
assertEquals(4, l.size);
assertEquals(4, l.get(3));
assertEquals(4, l.get(2));
assertEquals(2, l.get(1));
assertEquals(2, l.get(0));
assertEquals(l.sentinel, l.sentinel.next.next.next.next.prev.prev.prev.prev);
}
}
这是我的IntList.java
/** A data structure to represent a Linked List of Integers.
* Each IntList represents one node in the overall Linked List.
* Encapsulated version.
*/
public class IntList {
/** The head of the list is the first node in the list. If the list
is empty, head is null **/
private IntListNode head;
private int size;
/** IntListNode is a nested class. It can be instantiated when associated with an instance of
* IntList.
* **/
public class IntListNode {
int item;
IntListNode next;
public IntListNode(int item, IntListNode next) {
this.item = item;
this.next = next;
}
}
public int getSize() {
return size;
}
public IntList() {}
public IntList(int[] initial) {
for (int i = initial.length - 1; i >= 0; i--) {
head = new IntListNode(initial[i], head);
}
size = initial.length;
}
/**
* Get the value at position pos. If the position does not exist, throw an
* IndexOutOfBoundsException.
* @param position to get from
* @return the int at the position in the list.
*/
public int get(int position) {
if (position >= size) throw new IndexOutOfBoundsException("Position larger than size of list.");
IntListNode curr = head;
while (position > 0) {
curr = curr.next;
position--;
}
return curr.item;
}
@java.lang.Override
public java.lang.String toString() {
return "IntList{" +
"head=" + head +
", size=" + size +
'}';
}
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof IntList)) return false;
if (!super.equals(object)) return false;
IntList intList = (IntList) object;
return size == intList.size &&
java.util.Objects.equals(head, intList.head);
}
/* Fill in below! */
/**
* Insert a new node into the IntList.
* @param x value to insert
* @param position position to insert into. If position exceeds the size of the list, insert into
* the end of the list.
*/
public void insert(int x, int position) {
// Fill me in!
//insert when the size of the list is 0
if (this.size == 0) {
head = new InListNode(x, head);
size++;
}
//insert at the beginning of the list
else if (position == 0) {
IntListNode new_node = new IntListNode(x, head);
head = new_node;
size++;
}
else {
IntListNode point = head;
while (position > 1 && point.next != null) {
point = point.next;
position--;
}
IntListNode newone = new IntListNode(x, point.next);
point.next = newone;
size++;
}
}
/**
* Merge two sorted IntLists a and b into one sorted IntList containing all of their elements.
* @return a new IntList without modifying either parameter
*/
public static IntList merge(IntList a, IntList b) {
// Fill me in!
return null;
}
/**
* Reverse the current list recursively, using a helper method.
*/
public void reverse() {
// Fill me in!
}
/* Optional! */
/**
* Remove the node at position from this list.
* @param position int representing the index of the node to remove. If greater than the size
* of this list, throw an IndexOutOfBoundsException.
*/
public void remove(int position) {
if (position >= size) throw new IndexOutOfBoundsException();
// fill me in
}
}
答案 0 :(得分:2)
试试这个:
档案&gt; 无效缓存/重新启动&gt; 无效并重新启动
答案 1 :(得分:0)
尝试从控制台运行测试:How to run JUnit test cases from the command line
如果有效,请删除idea/
文件夹和*.iml
文件(如果存在)。确保您使用的是最新版本的IDE并重新导入。
答案 2 :(得分:0)
我的问题是依赖关系。
转到您的pom.xml文件,然后在</build>
下添加:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>