【问题标题】:How to write unit testing case for classes in the grails-app/utils folder in Grails 2.3.0如何为 Grails 2.3.0 中 grails-app/utils 文件夹中的类编写单元测试用例
【发布时间】:2013-09-27 02:15:48
【问题描述】:

我在 grails-app/utils 中编写了一个实用程序类:

package com.demo.formatter

class FooFormatter {
    static def foo() {
        return true
    }
}

并且,在 test/unit 中编写一个单元测试用例:

package com.demo.test.formatter

@RunWith(JUnit4)
class FooFormatterTests {
    @Test
    void testFoo() {
        AssertTrue(FooFormatter.foo())
    }
}

然后,使用 Intellij Idea IDE 运行测试用例,但我总是收到如下错误消息:

Class not found: "com.demo.test.formatter.FooFormatterTests" 

我是不是做错了什么?

谢谢

【问题讨论】:

  • 你的测试文件中有包声明吗?它与目录布局匹配吗?
  • 是的,我的包是 com.demo.test.formatter

标签: unit-testing grails groovy


【解决方案1】:

此测试在 IntelliJ 12.* 中运行良好(测试和 util 类在同一个包中并在 v2.2.4 中测试)

@RunWith(JUnit4)
class FooFormatterTests {
    @Test
    void testFoo() {
        assert FooFormatter.foo()
    }
}

尝试从console/command 行与grails test-app 进行测试。

【讨论】:

    猜你喜欢
    • 2015-03-03
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-13
    • 2016-11-08
    • 1970-01-01
    相关资源
    最近更新 更多