2

私はEclipse + Selenium WebDriver + TestNGを使用しています

これは私のクラス構造です:

class1
{
@test (invocation count =4)
method1()

@test (invocation count =4)
method2()

}

私の testing.xml ファイル:

<classes>
<class name="tests.class1">
<methods>
<include name="method1" />
<include name="method2" />
</methods>
</class>
</classes>

現在の testing.xml を実行すると、テストの順序は次のようになります。 method1 method1 method1 method1 method2 method2 method2 method2

しかし、テストを次の順序で実行したい: method1 method2 method1 method2 method1 method2 method1 method2

望ましい結果を達成するために私を導いてください。どうもありがとう。

4

3 に答える 3

4

ドキュメントdependsOnGroupsで " " を調べてください。

于 2012-07-17T02:28:45.730 に答える
3

TestNG の「優先度」を次のように使用することもできます。

@Test(priority = -19)
public void testMethod1(){
//some code
}
@Test(priority = -20)
public void testMethod2(){
//some code
}

[注: このテスト方法の優先度。優先度の低いものが最初にスケジュールされます]

したがって、上記の例では、testMethod2 が最初に実行され、-19 よりも小さい -20 として実行されます。

詳細については、http: //testng.org/doc/documentation-main.html#annotationsを参照してください。

于 2012-08-07T09:37:39.460 に答える
1

もちろん作り方はたくさんあります。例:

import java.lang.reflect.Method;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class ABC {

    @Test(invocationCount=12)
    public void uno(){
        System.out.println("UNO");
    }
    @AfterMethod()
    public void sec(Method m){
        if(m.getName().equals("uno"))
        System.out.println("SEC");
    }
}

そしてスイート:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test" parallel="none" >
    <classes>
      <class name="aaa.ABC">
          <methods>
              <include name="uno">
          </methods>
      </class>
    </classes>
  </test> <!-- Test -->
</suite>

dependsOnMethodthenを使用すると、すべての呼び出しの後にメソッドが実行されることに注意してください。例えば:

@Test(invocationCount=3)
public void uno(){
    System.out.println("UNO");
}
@Test(dependsOnMethods={"uno"})
public void sec(){

    System.out.println("SEC");
}

と:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test" parallel="none" >
    <classes>
      <class name="aaa.ABC">
          <methods>
              <include name="uno"/>
                 <include name="sec"/>
          </methods>
      </class>
    </classes>
  </test> <!-- Test -->
</suite>

あげる:

UNO
UNO
UNO
SEC

===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================

テストをテストする場合はverbose ="3"、スイートの conf で使用してください。例:

<suite name="Suite" parallel="none" verbose="3">

これは完全なログを有効にしているためです。

于 2015-02-20T13:28:12.333 に答える