result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp()); result.setSuiteName(test.suiteName()); result.setTestName(test.testName()); result.setSequential(test.sequential()); result.setSingleThreaded(test.singleThreaded());
result.setExpectedExceptionsMessageRegExp(test.expectedExceptionsMessageRegExp()); result.setSuiteName(test.suiteName()); result.setTestName(test.testName()); result.setSingleThreaded(test.singleThreaded()); result.setRetryAnalyzer(test.retryAnalyzer());
private void checkClassAnnotations(List<String> errors, Set<Class> processedClasses, ITestNGMethod m) { // Class of the test instance Class<?> testClass = m.getTestClass().getRealClass(); // Check that the test instance's class matches the XmlTest's support class // They can be different if a test inherits a @Factory method and doesn't override it // Ignore multiple classes in the same XmlTest, which can happen when running from the IDE // or when the testName is incorrect (handled below) if (m.getXmlTest().getXmlClasses().size() == 1) { Class xmlClass = m.getXmlTest().getXmlClasses().get(0).getSupportClass(); if (xmlClass != testClass && processedClasses.add(xmlClass)) { errors.add("Class " + xmlClass.getName() + " must override the @Factory method from base class " + testClass.getName()); return; } } if (!processedClasses.add(testClass)) return; // Check that the testName in the @Test annotation is set and matches the test class // All tests with the same testName or without a testName run in the same XmlTest // which means they also run in the same thread, not in parallel Test annotation = testClass.getAnnotation(Test.class); if (annotation == null || annotation.testName().isEmpty()) { errors.add("Class " + testClass.getName() + " does not have a testName"); return; } if (!annotation.testName().contains(testClass.getSimpleName())) { errors.add("Class " + testClass.getName() + " has an invalid testName: " + annotation.testName()); } }
private static TestMetadata findTestMetadata( Class<?> testClass ) { TestMetadata result = new TestMetadata(); if ( HAS_TEST_ANNOTATION_ON_CLASSPATH ) { Test testAnnotation = findAnnotation( testClass, Test.class ); if ( null != testAnnotation ) { if ( !StringUtils.isBlank( testAnnotation.suiteName() ) ) { result.suiteName = testAnnotation.suiteName(); } if ( !StringUtils.isBlank( testAnnotation.testName() ) ) { result.testName = testAnnotation.testName(); } } } return result; }
private static TestMetadata findTestMetadata( Class<?> testClass ) { TestMetadata result = new TestMetadata(); if ( HAS_TEST_ANNOTATION_ON_CLASSPATH ) { Test testAnnotation = findAnnotation( testClass, Test.class ); if ( null != testAnnotation ) { if ( !StringUtils.isBlank( testAnnotation.suiteName() ) ) { result.suiteName = testAnnotation.suiteName(); } if ( !StringUtils.isBlank( testAnnotation.testName() ) ) { result.testName = testAnnotation.testName(); } } } return result; }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { try { if (ListenerManager.isCurrentMethodSkipped(this)) { logger.exiting(ListenerManager.THREAD_EXCLUSION_MSG); return; } Test testMethod = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class); if (testMethod != null) { String testName = testMethod.testName(); if (StringUtils.isNotEmpty(testName)) { testResult.setAttribute(TEST_NAME_KEY, testName); } } } catch (Exception e) { //NOSONAR logger.log(Level.WARNING, "An error occurred while processing beforeInvocation: " + e.getMessage(), e); } }