Распечатайте журналы Reporter @BeforeMethod и @AfterMethod в электронном отчете о тестировании - PullRequest
0 голосов
/ 30 января 2020

Я выполняю некоторый код очистки в методе testng. Все гладко, но журналы не печатаются в электронном отчете. Но это печатает на консоли. Есть ли способ напечатать журналы метода before и after в отчете, который можно отправить по электронной почте. html

Предоставление примера кода

import java.io.IOException;
import java.lang.reflect.Method;

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

public class AutoItTest {
     @BeforeMethod(alwaysRun = true)
        public void initialize(Method method) {
         Reporter.log("Reporter before");
            String methodName = method.getName();
            int parameterCount = method.getParameterCount();
            String className = this.getClass().getCanonicalName();
            Reporter.log("methodName: "+methodName);
            Reporter.log("parameterCount: "+parameterCount);
            Reporter.log("className: "+className);
            long threadId = Thread.currentThread().getId();
            Reporter.log("threadId before: "+threadId);
            Test test = method.getAnnotation(Test.class);
            if (test == null) {
                return;
            }
            Reporter.log(test.testName() + " is currently running");
            Reporter.log(test.description() + " was its description");
        }

        @AfterMethod(alwaysRun = true)
        public void uninitialize(Method method) {
        Reporter.log("Reporter after");
            String methodName = method.getName();
            int parameterCount = method.getParameterCount();
            String className = this.getClass().getCanonicalName();
            long threadId = Thread.currentThread().getId();
            Reporter.log("threadId after: "+threadId);
            Reporter.log("methodName: "+methodName);
            Reporter.log("parameterCount: "+parameterCount);
            Reporter.log("className: "+className);
        }

        @Test(groups = "vdi")
        public void VDITest() throws IOException, Exception {
            Reporter.log("VDITest");
            Reporter.log("Reporter VDITest");
            long threadId = Thread.currentThread().getId();
            Reporter.log("threadId VDITest: "+threadId);
        }

        @Test(groups = "vdi")
        public void VDITest123() throws IOException, Exception {
            Reporter.log("VDITest123");
            long threadId = Thread.currentThread().getId();
            Reporter.log("threadId VDITest123: "+threadId);
        }
}

Emailable report

Я хочу как-то объединить журналы до и после метода

1 Ответ

0 голосов
/ 21 февраля 2020

Я нашел ответ

@AfterMethod
public void reportTest(ITestResult result) {
  Reporter.setCurrentTestResult(result);
  Reporter.log("Message to be printed");
}

Я добавил Reporter.setCurrentTestResult(result); в @BeforeMethod и @AfterMethod, а также в последовательные журналы, напечатанные в электронном отчете.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...