2010-04-29 14 views
24

मेरे पास PHPUnit के लिए निम्न, बहुत सरल, XML कॉन्फ़िगरेशन है:Xml कॉन्फ़िगरेशन में PHPUnit परीक्षण सूट से फ़ाइल को कैसे बाहर निकालें?

<phpunit bootstrap="/_tests/TestAutoload.php"> 
    <testsuites> 
     <testsuite name="Unit Tests"> 
      <directory suffix=".php">_tests</directory> 
     </testsuite> 
    </testsuites> 
</phpunit> 

परीक्षण सूट से इस निर्देशिका में कुछ फ़ाइल को बाहर कैसे निकालें? मैंने <exclude> और <blacklist> कोशिश की, लेकिन ऐसा लगता है कि यह इस संदर्भ में काम नहीं करता है। Xzx13 एक से भी कोई अन्य दस्तावेज नहीं मिला, जिसमें इसके बारे में कुछ भी उल्लेख नहीं है। इसके अलावा, यह विन्यास पूरी तरह से काम करता है।

+0

आप एक या अधिक चल रहा से बचने के लिए कोशिश कर रहे हैं अपने परीक्षण? –

+0

हां, यह वही है जो मैं करने की कोशिश कर रहा हूं। 1 टेस्ट क्लास = 1 फ़ाइल। –

उत्तर

28

तरीके नहीं एक विशेष परीक्षण चलाने के लिए की एक संख्या हैं - तो इसे चलाने रास्ता नहीं हो सकता है कभी नहीं है एक काली सूची में डालने - यह संपादन का मतलब बदल रहा है के रूप में काली सूची, और आप अक्सर इसे संस्करण नियंत्रण में और बाहर उछालते हुए समाप्त कर देंगे।

कई अन्य तरीके कि अधिक उपयुक्त हो सकता है:

एक परीक्षण अभी तक चलाने के लिए तैयार नहीं है, तो:

$this->markTestIncomplete('This test has not been implemented yet.'); 

अगर कोई बाहर कारण यह नहीं होना चाहिए चलाएं, इसे छोड़ दें:

if (!extension_loaded('mysqli')) { 
    $this->markTestSkipped('The MySQLi extension is not available.'); 
} 

आप इसे setUp() फ़ंक्शन में भी डाल सकते हैं, इसलिए यह परीक्षण-परीक्षण में सभी परीक्षणों को छोड़ देगा।

आप एक परीक्षण पिछले एक सफल होने पर निर्भर कर सकते हैं:

public function testEmpty() 
{ 
    $stack = array(); 
    $this->assertTrue(empty($stack)); 
    return $stack; // also sends this variable to any following tests - if this worked 
} 
/** 
* only runs if testEmpty() passed 
* 
* @depends testEmpty 
*/ 
public function testPush(array $stack) 
{ 
} 

@group -name- एनोटेशन का सर्वोत्तम उपाय विशेष रूप से बंद करें, या परीक्षण में से एक समूह को चलाने के लिए में से एक है

/** 
* @group database 
* @group remoteTasks 
*/ 
public function testSomething() 
{ 
} 

testSomething() दो समूहों में है, और या तो कमांड लाइन (या config.xml में) --exclude-group पैरामीटर पर जोड़ा जाता है। यह नहीं चलाया जाएगा। इसी तरह, आप केवल एक विशेष समूह से संबंधित परीक्षण चला सकते हैं - एक सुविधा के बाद नामित, या बग रिपोर्ट।

+0

"@ ग्रुप" बिल्कुल वही था जो मैं ढूंढ रहा था। धन्यवाद! –

+0

मैं चाहता हूं कि @ ग्रुप ने कॉन्फ़िगरेशन में phpunit नोड के अलावा testuite नोड के अंदर काम किया। मेरे पास एक परीक्षण था जिसे सभी अन्य परीक्षणों के लिए स्थिर वैर सेट करने से पहले चलाने की आवश्यकता थी। इसलिए मैंने एक टेस्ट क्लास में एक टेस्ट क्लास को RunFirst.php नाम से रखा और मेरे कॉन्फ़िगरेशन को एक सूट में चलाने के लिए संशोधित किया, लेकिन सभी अन्य सूट से पहले। – b01

+0

@ समूह के लिए धन्यवाद! – timbroder

-4

अरे वहाँ, सुनिश्चित करें कि आपने व्हाइटलिस्ट में अपना बहिष्कार रखा है। उदाहरण:

<phpunit> 
    <filter> 
     <blacklist> 
      <directory suffix=".php">/not/even/looked/at/</directory> 
     </blacklist> 
     <whitelist> 
      <directory suffix=".php">/path/to/test/dir/</directory> 
      <exclude> 
       <file suffix=".php">/path/to/fileToExclude.php</file> 
      </exclude> 
     </whitelist> 
    </filter> 
</phpunit> 

http://www.phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.blacklist-whitelist

+13

यह केवल कोड कवरेज के लिए काम करता है, न कि परीक्षण के लिए। –

6

इस PHPUnit कॉन्फ़िगरेशन-फ़ाइल को व्हाट करें मैंने बहुत अच्छे अनुभव किए हैं।

<?xml version="1.0" encoding="UTF-8"?> 
<phpunit 
    convertErrorsToExceptions="true" 
    convertNoticesToExceptions="true" 
    convertWarningsToExceptions="true" 
    colors="true" 
    processIsolation="true" 
    stopOnFailure="true" 
    syntaxCheck="false" 
    backupGlobals="false" 
    bootstrap="test-bootstrap.php"> 
    <testsuites> 
     <testsuite name="php-dba-cache"> 
      <directory suffix="Test.php">tests</directory> 
     </testsuite> 
    </testsuites> 
    <logging> 
     <log type="coverage-html" 
      target="build/coverage" 
      charset="UTF-8" 
      yui="true" 
      highlight="true" 
      lowUpperBound="35" 
      highLowerBound="70"/> 
    </logging> 
    <filter> 
     <whitelist addUncoveredFilesFromWhitelist="true"> 
      <directory suffix=".php">src</directory> 
      <exclude> 
      <file>test-bootstrap.php</file> 
      </exclude> 
     </whitelist> 
    </filter> 
</phpunit> 

https://github.com/gjerokrsteski/php-dba-cache

+5

इस कॉन्फ़िगरेशन में आप dirs/फ़ाइलों को छोड़कर कहां हैं? टैग कोड कवरेज के लिए हैं। –

4

phpunit documentation थोड़ा minimalistic जब यह एक testsuite में बहिष्कार करने के लिए आता है। जाहिर है, केवल संपूर्ण निर्देशिका को बाहर रखा जा सकता है लेकिन व्यक्तिगत फ़ाइलें नहीं है। गलत साबित होने के लिए मुझे बहुत खुशी होगी। लगता है कि वर्कअराउंड @ ग्रुप फीचर का उपयोग posted above एलीस्टर बुलमैन द्वारा किया जा रहा है।

यह उन दर्द सूटों में प्रत्येक परीक्षण को टैग करने की आवश्यकता है, जिसे मैं रखना चाहता हूं।

15

फ़ाइल नाम TestCase.php को बाहर करने के लिए।

अपने phpunit.xml

<testsuites> 
    <testsuite name="BLABLA"> 
     <directory suffix=".php">./tests</directory> 
     <exclude>./tests/TestCase.php</exclude> 
    </testsuite> 
</testsuites> 

यहाँ के साथ काम करने a real-live test-suite से एक अतिरिक्त अंश मैं यह पुष्टि कर सकते हैं से जोड़ें:

... 
    <testsuites> 
     <testsuite name="n98-magerun-tests"> 
      <directory>./tests</directory> 
      <exclude>tests/N98/Magento/Command/Installer/UninstallCommandTest.php</exclude> 
     </testsuite> 
    ... 
+0

क्या यह वास्तव में आपके लिए काम करता है? पिछली टिप्पणी के अनुसार (http://stackoverflow.com/a/15632735/2314626) निर्देशिकाओं के लिए काम बहिष्कृत करें। आपकी प्रस्तावित कॉन्फ़िगरेशन अभी भी विफल रहता है: कक्षा "टेस्टकेस" में कोई परीक्षण नहीं मिला। –

+0

@ एलनरूसुसामा: हां यह वास्तव में काम करता है। वह * पिछली टिप्पणी * वास्तव में साल पहले से एक जवाब है कि यहां तक ​​कि गलत साबित होना भी begs। – hakre

+0

पुष्टि की। हो सकता है कि यह काम करने के लिए उपयोग नहीं किया गया था, लेकिन यह निश्चित रूप से phpunit 5.3 के साथ करता है, साथ ही साथ सबसे सरल, स्पष्ट उत्तर भी होता है। – petercoles

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