当前位置: 首页 > 知识库问答 >
问题:

IntelliJ:找不到类:“”空测试套件

聂永怡
2023-03-14

我是刚到爪哇的。我正在做我的学校项目,我遇到了这个问题与错误消息。

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
}
}

共有1个答案

宣星光
2023-03-14

试试看:

文件>使缓存无效/重新启动>使缓存无效并重新启动

 类似资料:
  • 问题内容: 我刚刚在我的大学开始计算机科学计划,而IntelliJ遇到了一些问题。当我尝试运行单元测试时,我收到消息 我还在屏幕的左侧看到一条消息,标题为“未找到测试”。我的测试代码在这里: 我的项目代码在这里: 我如何才能使测试正常工作?我正在使用IntelliJ IDEA CE的最新版本。 问题答案: 因此,我的问题是文件夹名称。我已将代码文件夹命名为Class 2016/2017,这是Int

  • 我是新的java。我正在我的学校项目,我遇到了这个问题与错误消息。 我以前做过这样的测试,他们奏效了。 我没有写所有的方法。我试图先运行文件。我已经寻找了解决方案,但没有一个适合我的情况。 下面是我的测试代码: 这是我的清单。JAVA

  • 我的项目代码在这里: 我怎样才能让我的测试发挥作用?我使用的是IntelliJ IDEA CE的最新版本。

  • 当我试图在Android Studio上运行用Kotlin编写的espresso测试时(直到3.2 Canary 9),我得到的错误是:Process finished with exit code 1 Class not found:“com.myproject.directoryofwinning.verifyappisawesometest”空测试套件。 奇怪的是,同一项目中的Java测试没

  • 我的项目是一个多模块分级项目,使用Scala。 测试类位于src/Test/scala/xxx/xxxx/xxx/xxxx/xxxxx/xxxxx下,每次尝试从IDE运行时,都会得到相同的错误: 测试类不是什么花哨的,简单的jUnit测试:

  • 我遇到一个问题,IntelliJ13.1.4在运行单元测试时,在模块的目录中找不到文件。 在回答之前请注意,我已经完成了以下所有操作: 该模块是一个分级项目,如果我运行,单元测试运行良好。 我过去在IntelliJ中成功地运行了这个单元测试,它找到了模块。(也许是Intellij的早期版本?) 我已经检查了IntelliJ模块设置,并且目录被标记为测试资源目录。(见下面的截图。) 我正在类中转储单