首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >IntelliJ :找不到类:"“空测试套件

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

Stack Overflow用户
提问于 2018-06-02 07:04:58
回答 2查看 5.8K关注 0票数 0

我是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
}
}
EN

回答 2

Stack Overflow用户

发布于 2018-06-02 07:39:34

尝试从控制台运行测试:How to run JUnit test cases from the command line

如果有效,请删除idea/文件夹和*.iml文件(如果存在)。确保您使用的是最新版本的IDE,然后重新导入。

票数 1
EN

Stack Overflow用户

发布于 2018-09-24 01:26:27

我的问题是依赖关系。转到您的pom.xml文件并在</build>下面添加

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50651971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档