java.lang.NullPointerException
at freemarker.template.TemplateException.getFTLInstructionStack(TemplateException.java:233)
at freemarker.template.TemplateException.printStackTrace(TemplateException.java:363)
at freemarker.template.TemplateException.printStackTrace(TemplateException.java:339)
at freemarker.template.TemplateException.printStackTrace(TemplateException.java:327)
at org.testng.internal.Utils.buildStackTrace(Utils.java:535)
at org.testng.internal.Utils.longStackTrace(Utils.java:519)
at org.testng.reporters.TestHTMLReporter.generateTable(TestHTMLReporter.java:155)
at org.testng.reporters.TestHTMLReporter.generateLog(TestHTMLReporter.java:311)
at org.testng.reporters.TestHTMLReporter.onFinish(TestHTMLReporter.java:40)
at org.testng.TestRunner.fireEvent(TestRunner.java:772)
at org.testng.TestRunner.afterRun(TestRunner.java:741)
at org.testng.TestRunner.run(TestRunner.java:509)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
当我通过maven运行测试时出现此错误,但是当我单独运行测试时,它很好。错误转储到target / surefire-reports中,转储文件为2019-07-18T15-47-53_893-jvmRun1.dump。当我尝试在通过的单元测试中捕获异常时,会出现此错误。我的项目中有Freemerker Dependency,但此异常属于freemarker。这是单元测试。
@Test(expectedExceptions = TemplateException.class)
public void getTemplate_Unsuccessfull_TemplateException() throws IOException, TemplateException {
//GIVEN
//WHEN
Mockito.when(configuration.getTemplate("someFile.ftl")).thenReturn(template);
Mockito.doThrow(TemplateException.class).when(template).process(Mockito.any(Map.class),Mockito.any(Writer.class));
//THEN
TemplateService.getTemplate("abcd@gmail.com","123456");
}
这是控制台输出
Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 23.743 s
[INFO] Finished at: 2019-07-18T16:42:41+05:30
[INFO] Final Memory: 47M/382M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20:test (default-test) on project ***: There are test failures.
[ERROR]
[ERROR] Please refer to F:\*****\Project\****\branches\Authentication_20190508\Service\***\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] null
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] null
我希望能通过maven成功运行所有测试。