默认情况下,单元测试和集成测试具有相同的名称

发布于 2025-01-05 06:07:20 字数 629 浏览 0 评论 0原文

在 Grails 中,单元测试和集成测试使用完全相同的命名约定生成,因此,如果您正在测试名为 Foo 的域类,则两个测试都会使用名称 FooTests 生成。 ,在同一个包中。是否期望我应该进行单元测试或集成测试,但不能同时进行两者?人们是否将集成测试与单元测试放在不同的包中,或者重命名?解决这个问题的首选方法是什么?

顺便说一句,我修改了 grails/scripts/_GrailsCreateArtifacts.groovy 来更改类的生成方式,以便让它生成不同的名称(后缀属性的值全部更改)。当类位于名为“集成”的文件夹中时,我不喜欢在名称中包含一些表示“集成”的内容,但这至少避免了手动重命名。

createIntegrationTest = { Map args = [:] ->
    def superClass = args["superClass"] ?: "GroovyTestCase"
    createArtifact(name: args["name"], suffix: "${args['suffix']}IntTests", 
        type: "Tests", path: "test/integration", superClass: superClass)
}

In Grails the unit tests and integration tests get generated with exactly the same naming convention, so that if you are testing a domain class named Foo both tests get generated with the name FooTests, in the same package. Is there an expectation I should have either a unit test or an integration test, but not both? Do people put their integration tests in a different package from their unit tests, or rename one? What's the preferred way to get around this?

btw I hacked on grails/scripts/_GrailsCreateArtifacts.groovy to change how the classes are generated in order to get it to generate different names (the value for the suffix property is all that changed). I don't like having to include something that means 'integration' in the name when the class is in a folder called 'integration', but this at least avoids having to do a manual rename.

createIntegrationTest = { Map args = [:] ->
    def superClass = args["superClass"] ?: "GroovyTestCase"
    createArtifact(name: args["name"], suffix: "${args['suffix']}IntTests", 
        type: "Tests", path: "test/integration", superClass: superClass)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再见回来 2025-01-12 06:07:21

我认为给他们一个不同的名字是正确的选择。

*IntTests 

或者

*IntegrationTests

I think giving them a different name is the right choice.

*IntTests 

or

*IntegrationTests
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文