Giter Site home page Giter Site logo

Comments (8)

tednaleid avatar tednaleid commented on August 27, 2024

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.

longwa avatar longwa commented on August 27, 2024

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.

longwa avatar longwa commented on August 27, 2024

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.

longwa avatar longwa commented on August 27, 2024

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.

 avatar commented on August 27, 2024

thanks for addressing this so quickly, I'll check this out on Monday and report back here

from build-test-data.

gregopet avatar gregopet commented on August 27, 2024

Upgrading to 2.0.5 fixed my unit tests failing, as well. Good work and thank you!

from build-test-data.

zyro23 avatar zyro23 commented on August 27, 2024

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.

tednaleid avatar tednaleid commented on August 27, 2024

Assuming this is fixed, please comment if there are still issues here.

from build-test-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.