2011-07-07 11 views
7

मुझे बस कुछ कमांड की आवश्यकता है जैसे "इस कमांड को चलाएं और कंसोल आउटपुट में कहीं भी यह स्ट्रिंग है, तो विफल हो जाएंगे"। क्या ऐसा कोई उपकरण है?क्या विंडोज बैच फाइलों के लिए यूनिट-टेस्ट फ्रेमवर्क है?

+1

देखें http://stackoverflow.com/questions/940497/how-to-do-tdd- और इकाई परीक्षण में powershell – TrueWill

उत्तर

4

ऐसा नहीं है कि मुझे पता है, लेकिन आप आसानी से किसी अन्य बैच स्क्रिप्ट में एक लिख सकते हैं।

call TestBatchScript.cmd > console_output.txt 
findstr /C:"this string" console_output.txt 

स्ट्रिंग मिलने पर% errorlevel% शून्य पर सेट करेगा, और स्ट्रिंग अनुपस्थित होने पर nonzero सेट करेगा। इसके बाद आप IF ERRORLEVEL 1 goto :fail के साथ परीक्षण कर सकते हैं और :fail लेबल के बाद जो भी कोड चाहते हैं उसे निष्पादित कर सकते हैं।

यदि आप ऐसे कई तारों के कॉम्पैक्ट मूल्यांकन चाहते हैं, तो आप || वाक्य रचना:

call TestBatchScript.cmd > console_output.txt 
findstr /C:"teststring1" console_output.txt || goto :fail 
findstr /C:"teststring2" console_output.txt || goto :fail 
findstr /C:"teststring3" console_output.txt || goto :fail 
findstr /C:"teststring4" console_output.txt || goto :fail 
goto :eof 

:fail 
echo You Suck! 
goto :eof 

या, आप भी आगे जाने के लिए और एक फाइल

call TestBatchScript.cmd > console_output.txt 
set success=1 
for /f "tokens=*" %%a in (teststrings.txt) do findstr /C:"%%a" console_output.txt || call :fail %%a 
if %success% NEQ 1 echo You Suck! 
goto :eof 

:fail 
echo Didn't find string "%*" 
set success=0 
goto :eof 
2

मैं खिड़कियों बैच इकाई परीक्षण के लिए एक पुस्तकालय बनाया है से तार की सूची पढ़ सकता। यह वर्तमान में अपने बचपन में है, लेकिन यह काम करता है और मैं इसका उपयोग करता हूं।

यह cmdUnit कहा जाता है और यह bitbucket पर परियोजना साइट से डाउनलोड किया जा सकता है:

https://bitbucket.org/percipio/cmdunit

1

मैं filter प्रकार आदेश के लिए निम्नलिखित का उपयोग करें:

बैच फ़ाइल foo.cmd के लिए, बनाने के निम्नलिखित फाइलें:

foo.in.txt:
हैलो

012,

foo.expected.txt:
हैलो दुनिया

foo.test.cmd:

@echo off 

echo Testing foo.cmd ^< foo.in.txt ^> foo.out.txt 

call foo.cmd <foo.in.txt> foo.out.txt || exit /b 1 

:: fc compares the output and the expected output files: 
call fc foo.out.txt foo.expected.txt || exit /b 1 

exit /b 0 

फिर भी चलाने foo.test.cmd

संबंधित मुद्दे