Eclipse 每个Junit测试都可以很好地工作,但是当试图让Suite-none工作时

Eclipse 每个Junit测试都可以很好地工作,但是当试图让Suite-none工作时,eclipse,junit,junit4,junit-runner,Eclipse,Junit,Junit4,Junit Runner,我正在使用eclipse,并使用JUnit4测试用例创建了两个测试类。 每个测试类都可以正常工作,现在我需要制作一个测试套件来运行这两个测试类。 这两个测试类的名称是:GuessManager.class和asciipcutre.class 因此,我添加了一个名为TestSuite的类,下面是类代码: package hangman; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(

我正在使用eclipse,并使用JUnit4测试用例创建了两个测试类。 每个测试类都可以正常工作,现在我需要制作一个测试套件来运行这两个测试类。 这两个测试类的名称是:GuessManager.class和asciipcutre.class 因此,我添加了一个名为TestSuite的类,下面是类代码:

package hangman;  

import org.junit.runner.RunWith;  
import org.junit.runners.Suite; 

@RunWith(Suite.class)  
@Suite.SuiteClasses({GuessManager.class, AsciiPicture.class })  
public class TestSuite  
{  

}  
当我尝试运行它时,两个测试类都会出现初始化错误 以下是相关屏幕截图:

知道我做错了什么吗?我相信这与我的TestSuite类有关,因为如果我直接运行它们,每个测试都可以工作。 此外,这些测试也不是基于一个或另一个

编辑: 以下是我的两个测试课程:

package hangman;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class AsciiPictureTest {

    AsciiPicture canvas;
    AsciiPicture pic;

    @Before
    public void setUp() throws Exception {
        canvas = new AsciiPicture(6, 4, '0');
        pic = new AsciiPicture(1, 1, '*');

    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testOverlay() throws IOException {
        for (int i = 0; i < canvas.height; i++) {
            for (int j = 0; j < canvas.width; j++) {

                // Initial the expected result as char 2d - array
                char[][] expected = CreatePicture(canvas.width, canvas.height, '0');

                // Put a '*' in specific location to imitate the result of the overlay function
                expected[i][j] = '*';       

                // Initial the canvas to 'blank' canvas
                canvas = new AsciiPicture(6, 4, '0');

                // Making the actual overlay at index[i][j]
                canvas.overlay(pic, j, i, ' ');

                // Checking if the expected is equal to actual by checking each one of the characters
                asciiPictureCharArrAssertEquals(canvas, expected);
            }
        }
    }
    @Test
    public void testPrint() throws IOException {
        // Defining ByteArratOutputStream for "catching" the data that will be printed
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        // Setting the out of "System" to ByteArrayOutputStream we just defined
        System.setOut(new PrintStream(out));

        // Printing the data to the new configured output
        canvas.print(System.out);

        // Defining and building the expected String
        String expectedOutput = "000000" + System.lineSeparator() + 
                                "000000" + System.lineSeparator() + 
                                "000000" + System.lineSeparator() + 
                                "000000" + System.lineSeparator();

        // Checking if what was printed is equal to what should be printed
        assertEquals(out.toString(), expectedOutput);

    }
    public char[][] CreatePicture(int width, int height, char bgChar) {
        char[][] picture = new char[height][];
        for (int i = 0; i < height; ++i) {
            picture[i] = new char[width];
            for (int j = 0; j < width; ++j)
                picture[i][j] = bgChar;
        }
        return picture;
    }
    public boolean asciiPictureCharArrAssertEquals(AsciiPicture actual, char[][] expected ) {
        for (int i = 0; i < expected.length; i++) {
            for (int j = 0; j < expected[0].length; j++) {
                char expectedChar = expected[i][j];
                char actualChar = actual.get(j, i);
                assertEquals(expectedChar, actualChar);
            }
        }
        return true;
    }

}
packagehangman;
导入静态org.junit.Assert.*;
导入java.io.ByteArrayOutputStream;
导入java.io.IOException;
导入java.io.PrintStream;
导入org.junit.After;
导入org.junit.Before;
导入org.junit.Test;
公共类ASCIIPITU重新测试{
帆布;
脑缺血;
@以前
public void setUp()引发异常{
画布=新的ASCIIPacture(6,4,'0');
pic=新的ASCIIPacture(1,1,“*”);
}
@之后
public void tearDown()引发异常{
}
@试验
public void testOverlay()引发IOException{
对于(int i=0;i
第二个测试:

package hangman;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.sun.net.httpserver.Authenticator.Success;

import hangman.GuessManagerContract.GuessResponse;

/**
 * @author 
 *
 */
public class GuessManagerTest {

    private GuessManager gm;
    private static final String CORRECT_WORD = "Test";
    private static final char INCORRECT_LETTER = 'k';
    private static final char CORRECT_LETTER = 't';
    private static final int NUMBER_OF_GUESSES = 10;

    /**
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception {
        gm = new GuessManager(CORRECT_WORD , NUMBER_OF_GUESSES);
    }

    /**
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testGetBadGuessesLeft() {
        GuessResponse gr;
        // First Case - Initial value equal to number passed to constructor
        assertEquals(NUMBER_OF_GUESSES, gm.getBadGuessesLeft());

        // Second Case - After one bad guess - number of guesses decreased by one
        gr = gm.getGuessResponse(INCORRECT_LETTER);                     // Guess letter which isn't in word
        if (gr != GuessResponse.GUESS_BAD) fail("Should result in bad guess but didn't"); 
        assertEquals(NUMBER_OF_GUESSES - 1 , gm.getBadGuessesLeft());

        // Third Case - After one good guess - number of guesses remains the same
        gr = gm.getGuessResponse(CORRECT_LETTER);                       // Guess letter which is in word
        if ((gr != GuessResponse.GUESS_GOOD)&&(CORRECT_WORD.chars().distinct().count() != 1)) fail("Should result in good guess but didn't");
        assertEquals(NUMBER_OF_GUESSES - 1 , gm.getBadGuessesLeft());
    }

    @Test
    public void testGetGuessResponseGood() {

        // First Case - a correct letter has been guessed ,
        //testing for correct GuessResponse and no change in mount of bad Guesses Left
        int currentBadGuessesLeft = gm.getBadGuessesLeft();
        if (CORRECT_WORD.chars().distinct().count() != 1) {
            assertEquals(GuessResponse.GUESS_GOOD , gm.getGuessResponse(CORRECT_LETTER));
        }
        else {
            assertEquals(GuessResponse.GUESS_WIN , gm.getGuessResponse(CORRECT_LETTER));
        }
        assertEquals(currentBadGuessesLeft , gm.getBadGuessesLeft());
    }
    @Test
    public void testGetGuessResponseBad() {
        // Second Case - a bad letter has been guessed ,
        //testing for correct GuessResponse and decrease by one in mount of bad Guesses Left
        int currentBadGuessesLeft = gm.getBadGuessesLeft();
        assertEquals(GuessResponse.GUESS_BAD , gm.getGuessResponse(INCORRECT_LETTER));
        assertEquals(currentBadGuessesLeft - 1 , gm.getBadGuessesLeft());
    }
    @Test
    public void testGetGuessResponseWin() {
        // Third Case - a wining letter has been guessed 
        //testing for correct GuessResponse and no change in mount of bad Guesses Left
        //int currentBadGuessesLeft = gm.getBadGuessesLeft();

        // Making a for loop for putting all the correct letters but the last wining letter
        for (int i = 0; i < CORRECT_WORD.chars().distinct().count() - 1 ; i++) {
            char currentLetter = CORRECT_WORD.charAt(i);
            if (i != CORRECT_WORD.chars().distinct().count() - 1) assertEquals(GuessResponse.GUESS_GOOD , gm.getGuessResponse(currentLetter));
            else assertEquals(GuessResponse.GUESS_WIN , gm.getGuessResponse(currentLetter));
        }
    }

        // When we get there is only one letter left before winning ,find it and check for win
        //char currentLetter = CORRECT_WORD.charAt(CORRECT_WORD.length() - 2);
        //assertEquals(GuessResponse.GUESS_WIN , gm.getGuessResponse(currentLetter));
        //System.out.println("Im here");
    @Test
        public void testGetGuessResponseLose() {
        // Forth Case - a bad letter has been guessed and only one guess left ,
        //testing for correct GuessResponse and decrease by one in mount of bad Guesses Left
        int currentBadGuessesLeft = gm.getBadGuessesLeft();
        int limit = gm.getBadGuessesLeft();

        // Making a for loop for guessing all the incorrect letters but the last losing letter
        for (int i = 0; i < limit - 1; i++) {
            assertEquals(GuessResponse.GUESS_BAD , gm.getGuessResponse(INCORRECT_LETTER));
            assertEquals(currentBadGuessesLeft - 1 , gm.getBadGuessesLeft());
            currentBadGuessesLeft = gm.getBadGuessesLeft();
        }

        // When we get there is only one letter left before winning ,find it and check for win
        assertEquals(GuessResponse.GUESS_LOSE , gm.getGuessResponse(INCORRECT_LETTER));
        assertEquals(0 , gm.getBadGuessesLeft());
    }



}
packagehangman;
导入静态org.junit.Assert.*;
导入org.junit.After;
导入org.junit.Before;
导入org.junit.Test;
导入com.sun.net.httpserver.Authenticator.Success;
导入hangman.GuessManagerContract.GuessResponse;
/**
*@作者
*
*/
公共类猜测管理器测试{
私人经理总经理;
私有静态最终字符串更正\u WORD=“Test”;
私有静态最终字符错误_字母='k';
私有静态最终字符正确_字母='t';
私有静态最终整数猜数=10;
/**
*@java.lang.Exception
*/
@以前
public void setUp()引发异常{
gm=新猜测管理器(正确的单词、猜测的数量);
}
/**
*@java.lang.Exception
*/
@之后
public void tearDown()引发异常{
}
@试验
public void testGetBadGuessLeft(){
猜测反应gr;
//第一种情况-初始值等于传递给构造函数的数字
assertEquals(猜测次数,gm.GetBadGuessLeft());
//第二种情况——在一次错误猜测之后——猜测次数减少了一次
gr=gm.getGuessResponse(不正确的字母);//猜测word中没有的字母
如果(gr!=GuessResponse.GUESS_BAD)失败(“应该导致错误猜测,但没有”);
assertEquals(猜测次数-1,gm.GetBadGuessLeft());
//第三种情况——经过一次好的猜测——猜测的次数保持不变
gr=gm.getGuessResponse(正确的字母);//猜测word中的字母
如果((gr!=GuessResponse.GUESS_GOOD)&&(CORRECT_WORD.chars().distinct().count()!=1))失败(“应该导致正确的猜测,但没有”);
assertEquals(猜测次数-1,gm.GetBadGuessLeft());
}
@试验
public void testGetGuessResponseGood(){
//第一种情况-猜中了正确的字母,
//测试是否有正确的猜测响应,以及剩余的错误猜测数量是否有变化
int currentBadGuessLeft=gm.GetBadGuessLeft();
如果(更正单词.chars().distinct().count()!=1){
assertEquals(猜响应。猜好,g
package hangman;  

import org.junit.runner.RunWith;  
import org.junit.runners.Suite; 

@RunWith(Suite.class)  
@Suite.SuiteClasses({GuessManagerTest.class, AsciiPictureTest.class })  
public class TestSuite  {  

}