我有一个带有单元测试和集成测试的 Grails 5.1.9 应用程序,我使用的是 IntelliJ IDEA 2022.3.3(终极版)。在 IntelliJ IDEA 中查看类(无论是 Grails 域类、服务还是控制器)时,有没有办法让 IntelliJ 识别该类的相关集成测试并能够看到下面列出的测试相关单元测试旁边的“测试”选项卡?
例如,我的项目中有以下类,上面的截图显示
SegmentServiceIntegrationSpec.groovy
没有列在“Segment Tests”下:
package com.example.segment
import grails.compiler.GrailsCompileStatic
import grails.gorm.transactions.Transactional
@GrailsCompileStatic
@Transactional
class SegmentService {
...
}
package com.example.segment
import grails.testing.services.ServiceUnitTest
import spock.lang.Specification
class SegmentServiceSpec extends Specification implements ServiceUnitTest<SegmentService> {
def setup() {
}
def cleanup() {
}
void "An example test passes"() {
expect: "basic addition to be correct"
2 + 2 == 4
}
...
}
package com.example.segment
import grails.gorm.transactions.Rollback
import grails.testing.mixin.integration.Integration
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.Specification
@Integration
@Rollback
class SegmentServiceIntegrationSpec extends Specification {
@Autowired SegmentService segmentService
void "test removeOldSegments"() {
given: "no segments have been saved"
assert Segment.count() == 0
when: "removeOldSegments is called"
Integer result = segmentService.removeOldSegments()
then: "the scheduled offering only has one segment"
result == 0
}
...
}
我只是好奇是否有注释或我可以添加到我的集成测试中的东西来清楚地说明正在测试的类,以便 IntelliJ 识别集成测试。
请注意,通过为
integrationTest
Gradle 任务使用 Gradle 运行配置,我能够在 IntelliJ 中毫无问题地运行我的集成测试,并且我的集成测试正在通过。我也知道在 IntelliJ IDEA 中双击 Shift 键是快速搜索文件或类的快捷方式