当前位置: 首页>>代码示例>>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;未经允许,请勿转载。