【发布时间】:2019-02-01 18:52:57
【问题描述】:
import org.junit.Test;
import static org.junit.Assert.*;
public class TestPalindrome {
// You must use this palindrome, and not instantiate
// new Palindromes, or the autograder might be upset.
static Palindrome palindrome = new Palindrome();
@Test
public void testWordToDeque() {
Deque d = palindrome.wordToDeque("persiflage");
String actual = "";
for (int i = 0; i < "persiflage".length(); i++) {
actual += d.removeFirst();
}
assertEquals("persiflage", actual);
}
}
public class Palindrome{
public Deque<Character> wordToDeque(String word){
ArrayDeque<Character> c = new ArrayDeque();
for (char d : word.toCharArray()){
c.addLast(d);
}
return c;
}
}
从技术上讲,wordToDeque 方法可以包含任何内容(例如返回 null),但它仍然只是给我“未找到主要错误”。这有点令人困惑。编译器识别 junit,因为我已将它添加到我的环境变量中。有谁知道为什么会这样?
【问题讨论】:
-
它仍然只是给我“没有发现主要错误”。你什么时候做什么?
-
您应该在您的 ide 中使用“Run as Test”或等效项来运行 TestPalindrome。运行测试不像运行可执行类。
-
@spi 你知道如何在 git bash 中作为命令执行此操作吗?我没有使用 ide。
-
查看链接的副本