當前位置: 首頁>>代碼示例>>Java>>正文


Java TestNG類代碼示例

本文整理匯總了Java中org.testng.TestNG的典型用法代碼示例。如果您正苦於以下問題:Java TestNG類的具體用法?Java TestNG怎麽用?Java TestNG使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TestNG類屬於org.testng包,在下文中一共展示了TestNG類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setTestSuites

import org.testng.TestNG; //導入依賴的package包/類
/**
 * Sets the test suite to run using the given URI reference. Three types of
 * references are supported:
 * <ul>
 * <li>A file system reference</li>
 * <li>A file: URI</li>
 * <li>A jar: URI</li>
 * </ul>
 * 
 * @param driver
 *            The main TestNG driver.
 * @param ets
 *            A URI referring to a suite definition.
 */
private void setTestSuites(TestNG driver, URI ets) {
    if (ets.getScheme().equalsIgnoreCase("jar")) {
        // jar:{url}!/{entry}
        String[] jarPath = ets.getSchemeSpecificPart().split("!");
        File jarFile = new File(URI.create(jarPath[0]));
        driver.setTestJar(jarFile.getAbsolutePath());
        driver.setXmlPathInJar(jarPath[1].substring(1));
    } else {
        List<String> testSuites = new ArrayList<String>();
        File tngFile = new File(ets);
        if (tngFile.exists()) {
            LOGR.log(Level.CONFIG, "Using TestNG config file {0}", tngFile.getAbsolutePath());
            testSuites.add(tngFile.getAbsolutePath());
        } else {
            throw new IllegalArgumentException("A valid TestNG config file reference is required.");
        }
        driver.setTestSuites(testSuites);
    }
}
 
開發者ID:opengeospatial,項目名稱:teamengine,代碼行數:34,代碼來源:TestNGExecutor.java

示例2: setUp

import org.testng.TestNG; //導入依賴的package包/類
@Before
public void setUp() throws IOException {
    resultsDir = folder.newFolder();
    AllureResultsUtils.setResultsDirectory(resultsDir);

    List<String> suites = new ArrayList<>();
    URL resource = getClass().getClassLoader().getResource("suite3.xml");
    assertNotNull("could not find suite3.xml", resource);

    //noinspection ConstantConditions
    suites.add(resource.getFile());

    TestNG testNG = new TestNG();
    testNG.setTestSuites(suites);
    testNG.setUseDefaultListeners(false);
    testNG.run();
}
 
開發者ID:allure-framework,項目名稱:allure1,代碼行數:18,代碼來源:AllureTestListenerSuiteNameTest.java

示例3: addListener

import org.testng.TestNG; //導入依賴的package包/類
/**
 * 
 * @param testNG testNG instance
 * @param existingListeners existing listeners list (TestListeners/SuiteListeners/ReportListeners/... list)
 * @param listenerClassName listener canonical name
 */
private void addListener(
                          TestNG testNG,
                          List<?> existingListeners,
                          String listenerClassName ) {

    Class<?> listenerClass;
    try {
        listenerClass = Class.forName(listenerClassName);
        if (!isListenerAlreadyAttached(existingListeners, listenerClass)) {
            Object listener = listenerClass.newInstance();
            testNG.addListener(listener);
            logger.info("Successfully attached listener \"" + listenerClassName + "\".");
        } else {
            logger.info("Skip attaching listener \"" + listenerClassName
                        + "\". It's already attached!");
        }
    } catch (Exception e) {
        logger.error("Error attaching listener: \"" + listenerClassName + "\".", e);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:27,代碼來源:InitTestHarness.java

示例4: verifyHappyPath

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void verifyHappyPath() {
    
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testPassed");
    testNG.run();
    
    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
    
    ITestResult result = tla.getPassedTests().get(0);
    assertNull(UnitTestArtifact.getCaptureState(result), "Artifact provider capture state should be 'null'");
    assertNull(UnitTestCapture.getArtifactPath(result), "Artifact capture should not have been requested");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例5: verifyCaptureOnFailure

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void verifyCaptureOnFailure() {
    
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("testFailed");
    testNG.run();
    
    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
    
    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
    assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例6: verifyCanNotCapture

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void verifyCanNotCapture() {
    
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("canNotCapture");
    testNG.run();
    
    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
    
    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAN_NOT_CAPTURE, "Incorrect artifact provider capture state");
    assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例7: verifyWillNotCapture

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void verifyWillNotCapture() {
    
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("willNotCapture");
    testNG.run();
    
    assertEquals(tla.getPassedTests().size(), 0, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 1, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
    
    ITestResult result = tla.getFailedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_FAILED, "Incorrect artifact provider capture state");
    assertFalse(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path should not be present");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例8: verifyOnDemandCapture

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void verifyOnDemandCapture() {
    
    ListenerChain lc = new ListenerChain();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{ArtifactCollectorTestCases.class});
    testNG.addListener((ITestNGListener) lc);
    testNG.addListener((ITestNGListener) tla);
    testNG.setGroups("onDemandCapture");
    testNG.run();
    
    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0, "Incorrect curve-graded success count");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Incorrect configuration method failure count");
    assertEquals(tla.getConfigurationSkips().size(), 0, "Incorrect configuration method skip count");
    
    ITestResult result = tla.getPassedTests().get(0);
    assertEquals(UnitTestArtifact.getCaptureState(result), CaptureState.CAPTURE_SUCCESS, "Incorrect artifact provider capture state");
    assertTrue(UnitTestCapture.getArtifactPath(result).isPresent(), "Artifact capture output path is not present");
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ArtifactCollectorTest.java

示例9: testAttributeHandOff

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void testAttributeHandOff() {
    
    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{HappyPathClass.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();
    
    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");
    
    assertEquals(tla.getPassedTests().size(), 2, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 0, "Incorrect skipped test count");
    
    assertEquals(HappyPathClass.fromBefore, HappyPathClass.VALUE, "Incorrect [before] value");
    assertEquals(HappyPathClass.fromMethod, HappyPathClass.VALUE, "Incorrect [method] value");
    assertEquals(HappyPathClass.fromAfter, HappyPathClass.VALUE, "Incorrect [after] value");
    
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:25,代碼來源:ExecutionFlowControllerTest.java

示例10: testSkipFromMethod

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void testSkipFromMethod() {
    
    ExecutionFlowController efc = new ExecutionFlowController();
    TestListenerAdapter tla = new TestListenerAdapter();
    
    TestNG testNG = new TestNG();
    testNG.setTestClasses(new Class[]{SkipFromMethod.class});
    testNG.addListener((ITestNGListener) efc);
    testNG.addListener((ITestNGListener) tla);
    testNG.run();
    
    assertEquals(tla.getFailedTests().size(), 0, "Unexpected test method failure");
    assertEquals(tla.getConfigurationFailures().size(), 0, "Unexpected configuration method failure");
    
    assertEquals(tla.getPassedTests().size(), 1, "Incorrect passed test count");
    assertEquals(tla.getFailedTests().size(), 0, "Incorrect failed test count");
    assertEquals(tla.getSkippedTests().size(), 1, "Incorrect skipped test count");
    assertEquals(tla.getSkippedTests().get(0).getName(), "testMethod", "Incorrect skipped test name");
    
    assertEquals(SkipFromMethod.fromBefore, SkipFromMethod.VALUE, "Incorrect [before] value");
    assertEquals(SkipFromMethod.fromMethod, SkipFromMethod.VALUE, "Incorrect [method] value");
    assertEquals(SkipFromMethod.fromAfter, SkipFromMethod.VALUE, "Incorrect [after] value");
    
}
 
開發者ID:Nordstrom,項目名稱:TestNG-Foundation,代碼行數:26,代碼來源:ExecutionFlowControllerTest.java

示例11: run

import org.testng.TestNG; //導入依賴的package包/類
@Override
public void run() {
	
	try {
		TestListenerAdapter tla = new TestListenerAdapter();
		TestNG testng = new TestNG();
		testng.setTestClasses(new Class[] { HybridTest.class });
		//testng.settes
		testng.addListener(tla);
		testng.run();
	}catch (Exception e) {
		e.printStackTrace();
		System.out.println("Thread " +  threadName + " interrupted.");
	}

	System.out.println("Thread " +  threadName + " exiting.");
}
 
開發者ID:mattecker,項目名稱:revature-automation-framework-remastered,代碼行數:18,代碼來源:TestThread.java

示例12: runTestAndAssertCounters

import org.testng.TestNG; //導入依賴的package包/類
@Test
public void runTestAndAssertCounters() throws Exception {
	final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
	final TestNG testNG = new TestNG();
	testNG.addListener(listener);
	testNG.setTestClasses(new Class<?>[] { this.clazz });
	testNG.setVerbose(0);
	testNG.run();

	assertEquals("Verifying number of test starts for test class [" + this.clazz + "].",
		this.expectedTestStartCount, listener.testStartCount);
	assertEquals("Verifying number of successful tests for test class [" + this.clazz + "].",
		this.expectedTestSuccessCount, listener.testSuccessCount);
	assertEquals("Verifying number of failures for test class [" + this.clazz + "].", this.expectedFailureCount,
		listener.testFailureCount);
	assertEquals("Verifying number of failed configurations for test class [" + this.clazz + "].",
		this.expectedFailedConfigurationsCount, listener.failedConfigurationsCount);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:FailingBeforeAndAfterMethodsTestNGTests.java

示例13: runTestClassAndAssertStats

import org.testng.TestNG; //導入依賴的package包/類
private void runTestClassAndAssertStats(Class<?> testClass, int expectedTestCount) {
	final int expectedTestFailureCount = 0;
	final int expectedTestStartedCount = expectedTestCount;
	final int expectedTestFinishedCount = expectedTestCount;

	final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();
	final TestNG testNG = new TestNG();
	testNG.addListener(listener);
	testNG.setTestClasses(new Class<?>[] { testClass });
	testNG.setVerbose(0);
	testNG.run();

	assertEquals("Failures for test class [" + testClass + "].", expectedTestFailureCount,
		listener.testFailureCount);
	assertEquals("Tests started for test class [" + testClass + "].", expectedTestStartedCount,
		listener.testStartCount);
	assertEquals("Successful tests for test class [" + testClass + "].", expectedTestFinishedCount,
		listener.testSuccessCount);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ClassLevelDirtiesContextTestNGTests.java

示例14: checkTestNGInClasspath

import org.testng.TestNG; //導入依賴的package包/類
public static boolean checkTestNGInClasspath(PsiElement psiElement) {
  final Project project = psiElement.getProject();
  final PsiManager manager = PsiManager.getInstance(project);
  if (JavaPsiFacade.getInstance(manager.getProject()).findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) {
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
      if (Messages.showOkCancelDialog(psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) !=
          Messages.OK) {
        return false;
      }
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
    if (module == null) return false;
    String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class)));
    ModuleRootModificationUtil.addModuleLibrary(module, url);
  }
  return true;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:TestNGUtil.java

示例15: run

import org.testng.TestNG; //導入依賴的package包/類
private void run()
{
    LOG.debug("running tempto with options: {}", options);
    if (options.isHelpRequested()) {
        parser.printHelpMessage();
        return;
    }

    XmlSuite testSuite = getXmlSuite();
    testSuite.setThreadCount(options.getThreadCount());
    setupTestsConfiguration();
    System.setProperty(CONVENTION_TESTS_DIR_KEY, options.getConventionTestsDirectory());
    TestNG testNG = new TestNG();
    testNG.setXmlSuites(singletonList(testSuite));
    testNG.setOutputDirectory(options.getReportDir());
    setupTestsFiltering(testNG);
    options.getConventionResultsDumpPath()
            .ifPresent(path -> System.setProperty(CONVENTION_TESTS_RESULTS_DUMP_PATH_KEY, path));
    testNG.run();
    if (testNG.hasFailure()) {
        System.exit(1);
    }
}
 
開發者ID:prestodb,項目名稱:tempto,代碼行數:24,代碼來源:TemptoRunner.java


注:本文中的org.testng.TestNG類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。