You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何运行JUnit测试用例时全部显示‘Test Ignored’?

测试用例全部显示‘Test Ignored’的问题

完成Personality项目后,我使用提供的测试用例验证output.txt的输出结果,未对测试用例做任何修改直接运行,结果所有测试用例均显示‘Test Ignored’。我不常使用测试用例,不确定是否需要自行创建类实例。我通过Personality类的PrintWriter生成了output.txt,原以为每个测试用例会对比output.txt的每行内容。

以下是部分被忽略的测试用例代码:

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class PersonalityTest {

    static Scanner in;

    @BeforeClass
    public static void load() throws FileNotFoundException {
        in = new Scanner(new File("output.txt"));
    }

    /**
     * Test of Betty output, of Personality file.
     */
    @Test
    public void aTestBettyAName() {
        System.out.println("Betty Test Name");
        String name = "Betty Boop:";
        assertEquals(name, in.nextLine().trim());

    }

    /**
     * Test of Betty output, of Personality file.
     */
    @Test
    public void aTestBettyBAns() {
        System.out.println("Betty Test Answers");
        String ans = "1A-9B 17A-3B 18A-2B 18A-2B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Betty output, of Personality file.
     */
    @Test
    public void aTestBettyCResult() {
        System.out.println("Betty Test Type");
        String res = "[90%, 15%, 10%, 10%] = ISTJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Snoopy output, of Personality file.
     */
    @Test
    public void bTestSnoopyAName() {
        System.out.println("Snoopy Test Name");
        String name = "Snoopy:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Snoopy output, of Personality file.
     */
    @Test
    public void bTestSnoopyBAnswer() {
        System.out.println("Snoopy Test Answers");
        String ans = "7A-3B 11A-9B 14A-6B 6A-14B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Snoopy output, of Personality file.
     */
    @Test
    public void bTestSnoopyCType() {
        System.out.println("Snoopy Test Type");
        String res = "[30%, 45%, 30%, 70%] = ESTP";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Bugs Bunny output, of Personality file.
     */
    @Test
    public void cTestBugsAName() {
        System.out.println("Bugs Bunny Test Name");
        String name = "Bugs Bunny:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Bugs Bunny output, of Personality file.
     */
    @Test
    public void cTestBugsBAnswers() {
        System.out.println("Bugs Bunny Test Answers");
        String ans = "8A-2B 11A-9B 17A-3B 9A-11B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Bugs Bunny output, of Personality file.
     */
    @Test
    public void cTestBugsCType() {
        System.out.println("Bugs Bunny Test Type");
        String res = "[20%, 45%, 15%, 55%] = ESTP";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Daffy Duck output, of Personality file.
     */
    @Test
    public void dTestDaffyAName() {
        System.out.println("Daffy Duck Test Name");
        String name = "Daffy Duck:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Daffy Duck output, of Personality file.
     */
    @Test
    public void dTestDaffyBAnswers() {
        System.out.println("Daffy Duck Test Answers");
        String ans = "0A-10B 16A-1B 16A-4B 17A-1B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Daffy Duck output, of Personality file.
     */
    @Test
    public void dTestDaffyCType() {
        System.out.println("Daffy Duck Test");
        String res = "[100%, 6%, 20%, 6%] = ISTJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of frumious bandersnatch output, of Personality file.
     */
    @Test
    public void eTestBandersnatchAName() {
        System.out.println("Bandersnatch Test Name");
        String name = "The frumious bandersnatch:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of frumious bandersnatch output, of Personality file.
     */
    @Test
    public void eTestBandersnatchBAnswers() {
        System.out.println("Bandersnatch Test Answers");
        String ans = "1A-6B 1A-19B 5A-15B 4A-14B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of frumious bandersnatch output, of Personality file.
     */
    @Test
    public void eTestBandersnatchCType() {
        System.out.println("Bandersnatch Test Type");
        String res = "[86%, 95%, 75%, 78%] = INFP";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Minnie Mouse output, of Personality file.
     */
    @Test
    public void fTestMinnieMouseAName() {
        System.out.println("Bandersnatch Test Name");
        String name = "Minnie Mouse:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Minnie Mouse output, of Personality file.
     */
    @Test
    public void fTestMinnieMouseBAnswers() {
        System.out.println("Bandersnatch Test Answers");
        String ans = "3A-6B 13A-5B 13A-6B 18A-1B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Minnie Mouse output, of Personality file.
     */
    @Test
    public void fTestMinnieMouseCType() {
        System.out.println("Bandersnatch Test Type");
        String res = "[67%, 28%, 32%, 5%] = ISTJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Luke Skywalker output, of Personality file.
     */
    @Test
    public void gTestLukeSkywalkerAName() {
        System.out.println("Luke Skywalker Test Name");
        String name = "Luke Skywalker:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Luke Skywalker output, of Personality file.
     */
    @Test
    public void gTestLukeSkywalkerBAnswers() {
        System.out.println("Luke Skywalker Test Answers");
        String ans = "1A-8B 7A-11B 14A-5B 15A-5B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Luke Skywalker output, of Personality file.
     */
    @Test
    public void gTestLukeSkywalkerCType() {
        System.out.println("Luke Skywalker Test");
        String res = "[89%, 61%, 26%, 25%] = INTJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Han Solo output, of Personality file.
     */
    @Test
    public void hTestHanSoloAName() {
        System.out.println("Han Solo Test Name");
        String name = "Han Solo:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Han Solo output, of Personality file.
     */
    @Test
    public void hTestHanSoloBAnswers() {
        System.out.println("Han Solo Test Answers");
        String ans = "2A-8B 9A-9B 11A-9B 15A-5B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**
     * Test of Han Solo output, of Personality file.
     */
    @Test
    public void hTestHanSoloCType() {
        System.out.println("Han Solo Test Type");
        String res = "[80%, 50%, 45%, 25%] = IXTJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

    /**
     * Test of Princess Leia output, of Personality file.
     */
    @Test
    public void iPrincessLeiaAName() {
        System.out.println("Princess Leia Test Name");
        String name = "Princess Leia:";
        assertEquals(name, in.nextLine().trim());
    }

    /**
     * Test of Princess Leia output, of Personality file.
     */
    @Test
    public void iPrincessLeiaBAnswers() {
        System.out.println("Princess Leia Test Answers");
        String ans = "2A-8B 10A-10B 9A-9B 19A-1B";
        assertEquals(ans, in.nextLine().trim());
    }

    /**ality file.

     * Test of Princess Leia output, of Personality file.
     */
    @Test
    public void iPrincessLeiaCType() {
        System.out.println("Princess Leia Test Type");
        String res = "[80%, 50%, 50%, 5%] = IXXJ";
        assertEquals(res, in.nextLine().trim());
        in.nextLine();
    }

//    /**Test of file existence, of Person

    @Test
    public void jTestFileExists() throws IOException {
        System.out.println("Check if File exists Test");
       String input = "wrongFile.txt stillwrong.txt personality.txt";
       ByteArrayInputStream inStream = new ByteArrayInputStream(input.getBytes());
        System.setIn(inStream);
        //Person p = new Person();
       System.setIn(System.in);
   }
}

测试结果截图:
测试结果截图1
测试结果截图2

内容的提问来源于stack exchange,提问作者Maybe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 03:18:12