나는 명령 프롬프트 솔루션을 요구하고 있지만 실제로 JUnit을 조사해야한다는 것을 알고 있습니다. 다양한 테스트 조건에 대해 훨씬 더 유지 보수가 용이 한 솔루션이 될 것입니다. 커맨드 라인을 사용한다면, 모든 입출력을 파싱해야합니다. 코드를 진정으로 테스트하려면 커맨드 라인 (stdin, stdout)의 중간 단계를 거칠 필요가 없습니다. 변수에 액세스 할 수 있으므로 Java 코드를 실행하는 Java 코드가 있어야합니다.
명령 줄을 사용하여 실제로 설정 한 경우 프로그램 실행 방법에 대한 자세한 정보를 제공해야합니다. 이 어둠 속에서 단지 샷 :
inputs.txt
Add
4
6
test.bat
@ECHO OFF
:: I just assume that your program prompts for input and waits for stdin
java YourMainClass <inputs.txt> testOutput.txt
:: Program prompts for an operation; "Add" is read from inputs.txt
:: Program prompts for values; "4" and "6" are read from inputs.txt
:: Program prints out the result, which is redirected to testOutput.txt
:: Now you have to read in the testOutput.txt file and look at the last line
FOR /F %%i IN (testOutput.txt) DO SET RESULT=%%i
:: The variable RESULT now contains your program's answer
:: Create a variable to compare your actual result with the expected result
SET EXPECTED=10
IF %RESULT% == %EXPECTED% ECHO "You were correct"
IF NOT %RESULT% == %EXPECTED% ECHO "You were not correct"
[이미 질문했습니다] (http://stackoverflow.com/questions/13937541/how-to-automate-command-prompt-application) 답변을 얻었습니다. StackOverflow에서는 이중 게시가 권장되지 않습니다. 대답이 마음에 들지 않았다면 질문을 수정해야합니다. – RustyTheBoyRobot