没有找到TestDataConfig.groovy,build-test-data插件在没有配置文件的情况下进行处理 [英] TestDataConfig.groovy not found, build-test-data plugin proceeding without config file

查看:115
本文介绍了没有找到TestDataConfig.groovy,build-test-data插件在没有配置文件的情况下进行处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



TestDataConfig.groovy未找到,build-test-data插件在没有配置文件的情况下执行



它在集成测试中很像魅力,但不是单元测试的一部分。我的意思是,'build'插件在单元测试中工作,但'TestDataConfig'没有填充默认值。

谢谢

解决方案

首先,您应该在您的BuildConfig.groovy

test中验证build-test-data的版本:build -test-data:2.0.3



其次,检查你的测试。如果您希望构建对象,您需要:

  import grails.buildtestdata.mixin.Build 
...
@TestFor(TestingClass)
@Build([TestingClass,SupportClass,AnotherClass])
class TestingClassTest {
@Test
void testMethod {
def tc1 = TestingClass。 build()
def sc1 = SuportClass.build()
def ac1 = AnotherClass.build()
}
}

第三,检查域约束,您可以在构建两个实例时进行一些属性验证,如独特的验证失败。您需要在代码中设置这些属性:

  def tc1 = TestingClass.build(uniqueProperty:'unique')
def tc2 = TestingClass.build(uniqueProperty:'special')


I am getting the following error when including in Mixin Build in unit tests:

TestDataConfig.groovy not found, build-test-data plugin proceeding without config file

it works like charm in the integration tests but not part of unit tests. I mean, 'build' plugin works itself in unit test but the 'TestDataConfig' is not populating default values

Thank You

解决方案

First you should verify the version from build-test-data in your BuildConfig.groovy

test ":build-test-data:2.0.3"

Second, check your test. If you want build objects you need:

import grails.buildtestdata.mixin.Build
...
@TestFor(TestingClass)
@Build([TestingClass, SupportClass, AnotherClass])
class TestingClassTest{
    @Test
    void testMethod{
        def tc1 = TestingClass.build()
        def sc1 = SuportClass.build()
        def ac1 = AnotherClass.build()
    }
}

Third, check the domains constraints, you could have some properties validations like unique that fails when you build two instances. You need set that properties in code:

def tc1 = TestingClass.build(uniqueProperty: 'unique')
def tc2 = TestingClass.build(uniqueProperty: 'special')

这篇关于没有找到TestDataConfig.groovy,build-test-data插件在没有配置文件的情况下进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆