Comments (8)
Looks like grails 2.1.4 has a pretty big change to how they're mocking domain classes in unit tests. The release notes specify that you need to manually @Mock
all domain classes that you want to work with.
I was able to get your test to pass by also calling @Mock
on the domain classes in addition to @Build
.
diff --git a/test/unit/btd/bug/BrochureTests.groovy b/test/unit/btd/bug/BrochureTests.groovy
index 2f2c03e..4502e2c 100644
--- a/test/unit/btd/bug/BrochureTests.groovy
+++ b/test/unit/btd/bug/BrochureTests.groovy
@@ -7,7 +7,8 @@ import org.junit.*
/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
-@Build([Brochure, PageTag])
+@Build([PageTag])
+@Mock([Brochure, PageTag])
class BrochureTests {
void testSomething() {
Not optimal, but apparently they did it for performance reasons. That change removes BTDs ability to "know" what classes are related to each other in unit tests and this is the unfortunate side effect. Integration tests should be fine, but for performance reasons the grails authors have made the decision to push the wiring knowledge onto the unit test to explicitly define.
from build-test-data.
I believe this is fixed in the 2.0.5 RC that I've been testing. I'll merge it into master and push out a release next week. I should have done it awhile ago but have been sidetracked. The changes make BTD more friendly with some of the recent grails changes.
-Aaron
On Apr 19, 2013, at 8:52 PM, Ted Naleid [email protected] wrote:
Looks like grails 2.1.4 has a pretty big change to how they're mocking domain classes in unit tests. The release notes specify that you need to manually @mock all domain classes that you want to work with.
I was able to get your test to pass by also calling @mock on the domain classes in addition to @build.
diff --git a/test/unit/btd/bug/BrochureTests.groovy b/test/unit/btd/bug/BrochureTests.groovy
index 2f2c03e..4502e2c 100644
--- a/test/unit/btd/bug/BrochureTests.groovy
+++ b/test/unit/btd/bug/BrochureTests.groovy
@@ -7,7 +7,8 @@ import org.junit.*
/**
See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
-@build([Brochure, PageTag])
+@build([PageTag])
+@mock([Brochure, PageTag])
class BrochureTests {void testSomething() {
Not optimal, but apparently they did it for performance reasons. That change removes BTDs ability to "know" what classes are related to each other in unit tests and this is the unfortunate side effect. Integration tests should be fine, but for performance reasons the grails authors have made the decision to push the wiring knowledge onto the unit test to explicitly define.—
Reply to this email directly or view it on GitHub.
from build-test-data.
I just tested the attached application with what is currently in the BTD develop branch and the test passes with no changes. The problem with 2.1.4 and later is that the mockDomain method changed in the grails mixins to take all fo the domains at once in order to optimize. BTD was always automatically mocking required, associated objects but in the new scheme those need to be determined entirely upfront and the newer method used or it doesn't seem to work properly. The latest code does that properly and is able to take advantage of the perf improvements in Grails at the same time.
Also, 2.0.5 fixes a number of other performance issues that were introduced in 2.0.3 and 2.0.4, mostly in unit tests.
from build-test-data.
I pushed out a 2.0.5 release which fixes the issues you are seeing. Please upgrade and let me know if you still have problems.
from build-test-data.
thanks for addressing this so quickly, I'll check this out on Monday and report back here
from build-test-data.
Upgrading to 2.0.5 fixed my unit tests failing, as well. Good work and thank you!
from build-test-data.
while 2.0.5 reduced the number of errors i see, i still got some MissingMethodExceptions for MyDomain.addToMyHasManys(). anyhow, adding @mock for those makes it work.
from build-test-data.
Assuming this is fixed, please comment if there are still issues here.
from build-test-data.
Related Issues (20)
- Feature Req: add a UnitTestDomainBuilder to work like DomainUnitTest
- Enhance "Includes", "Excludes" & "Expand" to work like JsonViews or Gorm-Tools
- Is TestDataConfig required or optional? HOT 1
- Problem with graph generation with field of type Map HOT 1
- Java 7 compatibility HOT 2
- Implement property resolver strategy
- [Naming Suggestion] Rename trait BuildDataTest to BuildTestData. HOT 2
- ValidateableDataBuilder#satisfyConstrained and unique vs. nullable vs. blank HOT 1
- TestDataConfig unitAdditionalBuild does not appear to be working HOT 1
- When calling a constructor with an empty string, the attribute is initialized as null HOT 1
- "Domain.build(save:false)" saves immediately
- Bean Validation annotation not supported
- Fix base tests and move main code base. HOT 10
- Wrong data generated on 2nd call to build() with email & presense of unique constraints HOT 3
- support example constraint. HOT 1
- Cast exception during test with build
- 3.3.0.RC1 requires compile scope HOT 3
- Feature Req: buildAll to populate all properties even if nullable:true is set on them HOT 1
- Feature Req: add ability to generate a Map of test data. HOT 1
- refactor and merge in some of TKVW's changes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from build-test-data.