이 testNG 테스트를 동적으로 만들 수 있지만 병렬로 유지하려면 어떻게해야합니까?

Aug 21 2020
public class FactoryTest {
    
    @Test  
    @Parameters("Row")
    public void run1(int row) throws MalformedURLException{           
        new Controller(row);
    }
    
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods">
  <test thread-count="2" name="factory test" parallel="methods">
    <classes>
      <class name="RealPackage.FactoryTest">
             <methods>
                    <include name="run1">
                        <parameter name="Row"  value="1"/>
                    </include>                
                </methods></class>
    </classes>
  </test> <!-- OfficialTestName -->
</suite> <!-- Suite -->

이것은 내가 실행해야하는 테스트 중 하나의 예입니다. 다른 테스트와 병렬로 실행해야합니다. 그래서 테스트에서 테스트 를 시작하는를 run1()만들고 Controller(row)행 번호를 전달합니다. new Controller(1)new Controller(2)new Controller(3)등 을 동시에 실행 하고 싶습니다 . Java 파일을 다음과 같이 변경하면이 작업을 수행 할 수 있습니다.

public class OfficialTest {
    
    @Test    
    public void run1() throws MalformedURLException{           
        new Controller(1);
    }
    
    @Test    
    public void run2() throws MalformedURLException{           
        new Controller(2);
    }
    
    @Test    
    public void run3() throws MalformedURLException{           
        new Controller(3);
    }
    
    @Test    
    public void run4() throws MalformedURLException{           
        new Controller(4);
    }
    
    @AfterMethod
    public void close() {
        System.out.println("closing");
    }
}

그러나 이것은 동적이 아닙니다. .NET Framework에 대해 모든 범위의 숫자를 사용하여 실행할 수 있어야합니다 row. 그래서 나는 이것을 처리 할 XML 파일을 생성 할 수있을 것이라고 생각했지만 그것이 병렬로 실행될 수 있을지 여전히 확실하지 않습니다.

답변

1 mastercool Aug 22 2020 at 03:29

이 문제를 해결할 수있었습니다.

public class ParallelTests 
{

    int row;
    
    @Parameters({"Row"})
    @BeforeMethod()
    public void setUp(int rowParam) throws MalformedURLException
    {           
       row = rowParam;
    }
    
    @Test
    public void RunTest() throws InterruptedException, MalformedURLException
    {
        new Controller(row);
    }

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="5" name="BlogSuite" parallel="tests">
<test name="Test 1">
<parameter name="Row" value="1"/>
    <classes>
      <class name="RealPackage.ParallelTests"/>
    </classes>
  </test> 
  <test name="Test 2">
<parameter name="Row" value="2"/>
    <classes>
      <class name="RealPackage.ParallelTests"/>
    </classes>
  </test> 
    <test name="Test 3">
<parameter name="Row" value="3"/>
    <classes>
      <class name="RealPackage.ParallelTests"/>
    </classes>
  </test> 
    <test name="Test 4">
<parameter name="Row" value="4"/>
    <classes>
      <class name="RealPackage.ParallelTests"/>
    </classes>
  </test> 
      <test name="Test 5">
<parameter name="Row" value="5"/>
    <classes>
      <class name="RealPackage.ParallelTests"/>
    </classes>
  </test>
  </suite>