2016-10-26 4 views
0

testng.xmlで定義されているparamterised値にアクセスできません。テストとメソッドレベルでパラメータを定義しました。他の同様のクエリから取得しましたが、エラーは残ります。 Error "パラメータ 'myName'は、parameterTestメソッドで@Testが必要ですが、@Optionalとマークされていないか、C:\ Windows \ Temp \ testng-eclipse-281832880 \ testng-customsuite.xmlの に定義されていません。testngのtestng.xmlからパラメータを渡す際にエラーが発生しました。

以下私のコードスニペット、続いてtestng.xmlとエラー

Code snippet for one and two params

testng.xml with both param types 1-at test and method level both, 2- at method level

+0

だだ、あなたはquiestion編集代わりに、スクリーンショットのコードexemplesを追加してください。 – RocketRaccoon

答えて

1

私は[同じクラスが同じ<test>タグに複数回含まれていないようにする必要があります。

ここ

package organized.chaos.testng; 

import org.testng.annotations.Parameters; 
import org.testng.annotations.Test; 

public class EmployeeTestNG { 
    @Parameters ({"and", "abc"}) 
    @Test 
    public void test1(String b, String a) { 
     System.err.println("****" + b + a); 
    } 

    @Test 
    @Parameters ("myName") 
    public void parameterTest(String myName) { 
     System.err.println("Parameterized value is " + myName); 
    } 
} 

サンプルはここでTestNGのスイートXMLは

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="employee-suite"> 
    <test name="Employee-test"> 
     <classes> 
      <class name="organized.chaos.testng.EmployeeTestNG"> 
       <parameter name="myName" value="TestNG"/> 
       <parameter name="and" value="KungFu"/> 
       <parameter name="abc" value="Panda"/> 
       <methods> 
        <include name="parameterTest"/> 
        <include name="test1"/> 
       </methods> 
      </class> 
     </classes> 
    </test> 
</suite> 

だここで出力

[TestNG] Running: 
    /Users/krmahadevan/githome/PlayGround/testbed/src/test/resources/employee.xml 
Parameterized value is TestNG 
****KungFuPanda 

=============================================== 
employee-suite 
Total tests run: 2, Failures: 0, Skips: 0 
=============================================== 


Process finished with exit code 0 
+0

yes thanx Krishnan私はタグの下でクラス名を一度しか使用しませんでした。問題は私がクラスを実行していたときでした。私はXML設定を実行したときに私のために働いた –

+0

@SAMINATAJ - それを受け入れるのを助けてもらえますか? –

関連する問題