【问题标题】:Maven error messages do not link to codeMaven 错误消息不链接到代码
【发布时间】:2014-06-15 19:09:03
【问题描述】:

我查看了 Google guice 库并将项目作为 Maven 项目导入到 eclipse Kepler 中。一切顺利。

当我运行 Run As > Maven 测试时

一次测试失败

Failed tests: 
  testInterceptingNonBridgeWorks(com.google.inject.MethodInterceptionTest).

And the link points to a text file that opens in the editor contains a bunch of exception messages such as 

-------------------------------------------------------------------------------
Test set: com.google.inject.MethodInterceptionTest
-------------------------------------------------------------------------------
Tests run: 10, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.043 sec <<< FAILURE!
testInterceptingNonBridgeWorks(com.google.inject.MethodInterceptionTest)  Time elapsed: 0.01 sec  <<< FAILURE!
junit.framework.AssertionFailedError: expected:<1> but was:<0>
    at junit.framework.Assert.fail(Assert.java:57)
    at junit.framework.Assert.failNotEquals(Assert.java:329)
    at junit.framework.Assert.assertEquals(Assert.java:78)
    at junit.framework.Assert.assertEquals(Assert.java:234)
    at junit.framework.Assert.assertEquals(Assert.java:241)
    at junit.framework.TestCase.assertEquals(TestCase.java:409)
    at com.google.inject.MethodInterceptionTest.testInterceptingNonBridgeWorks(MethodInterceptionTest.java:271)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at junit.framework.TestCase.runTest(TestCase.java:176)
    at junit.framework.TestCase.runBare(TestCase.java:141)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:255)
    at junit.framework.TestSuite.run(TestSuite.java:250)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)

我的问题是 - 有没有办法让此类构建错误直接链接到 maven 项目中的代码行号,就像普通 Java 自然项目的工作方式一样?

脱胎换骨

【问题讨论】:

    标签: eclipse unit-testing maven build compiler-errors


    【解决方案1】:

    在 Eclipse 中,只需作为 junit 测试运行,您将在 JUnit 窗格中获得适当的支持。否则,从故障堆栈跟踪中回溯,您可以轻松查看失败的位置:

    at com.google.inject.MethodInterceptionTest.testInterceptingNonBridgeWorks(MethodInterceptionTest.java:271)
    

    使用 ctrl-shift-T 打开文件 -> MIT

    使用 ctrl-L -> 271 定位错误

    【讨论】:

    • 我有点困惑,为什么无法从 maven 消息中直接链接。有没有办法做到这一点?因为对于大量的多模块项目来说,从错误/异常消息中定位源文件是相当痛苦的
    • Maven 是一个命令行工具,在标准控制台上输出。您不能在控制台窗格中编写链接。
    • Eclipse,另一方面,可能会增强输出并在行上放置标记以查明来源,但那是 Eclipse。
    • 运行方式 -> Maven 测试,由 Eclipse 插件提供,它将捕获 Maven 控制台并呈现它。
    • 这就是为什么我建议 run as -> 单元测试,它使用 eclipse JUnit 插件。这将是相同的测试,但不同的 eclipse 插件..
    猜你喜欢
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2013-04-12
    • 2018-02-02
    相关资源
    最近更新 更多