|
View:
New views
20 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
[ANN] Testing Plugin 0.2 sneakily releasedHi,
I have released version 0.2 of the testing plugin. This doesn't contain either the tag lib stuff or the URL mapping test classes, but it does include: * A bunch of bug fixes * getAll() static method for domain classes * More render() implementations for controllers * Support for mocking command objects * Added constructor and ".properties" based data binding * ".errors" on domain classes and command objects is a real "Errors" instance * save() method calls validate() and adds the new domain instance to the list of test instances * ".session" is now an implementation of HttpSession, not a map svn HEAD contains support for "withFormat" in controllers and it has basic support for testing tag libraries. Not well tested yet though. Now all I need is some time to document this stuff. Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedPeter,
w00t! and great stuff regarding the Constructor stuff.. Am curious what you r provided does .. We were running into a problem yesterday with MockFor not actually mocking the target classes constructor - but infact executing the real constructor (and we understand how this could be hard to avoid)... Rather annoying when classes out of your control have huge gobs of logic ibn their constructor (eg: groovyws.WSClient!!!) grrr... J ps: to use this, do i re-install the plugin.. or assemble from source? On Tue, Sep 23, 2008 at 11:30 AM, Peter Ledbrook <peter@...> wrote: Hi, |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released
found, thx http://plugins.grails.org/grails-testing/trunk/ |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedI'm getting the following exception in all my controller tests:
Cannot cast object 'org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpSession@11fd699' with class 'org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpSession' to class 'java.util.Map' ... at grails.test.ControllerUnitTestCase.setUp(ControllerUnitTestCase.groovy:76) Looks like the plugin now attaches a GrailsMockHttpSession to the controller but the property on ControllerUnitTestCase is still declared as Map. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released> I'm getting the following exception in all my controller tests:
> > Cannot cast object > 'org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpSession@11fd699' > with class > 'org.codehaus.groovy.grails.plugins.testing.GrailsMockHttpSession' > to class 'java.util.Map' > ... > at grails.test.ControllerUnitTestCase.setUp(ControllerUnitTestCase.groovy:76) > > Looks like the plugin now attaches a GrailsMockHttpSession to the > controller but the property on ControllerUnitTestCase is still > declared as Map. I knew I'd fixed that, but unfortunately after the release. Oh well, a bit of a rush job on that release. FYI svn HEAD uses MockHttpSession rather than GrailsMockHttpSession. If I package up svn HEAD as 0.3-SNAPSHOT, do you mind giving it a whizz? I'll try it as well, and if that's fine, I'll release as 0.3. The URL mapping stuff can go into 0.4. Definitely need to flesh out the test cases for GrailsUnitTestCase et al. Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedYeah, that works better for me.
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released> Yeah, that works better for me.
grails install-plugin http://plugins.grails.org/grails-testing/trunk/grails-testing-0.3-SNAPSHOT.zip -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedOn Tue, Sep 23, 2008 at 12:24 PM, Peter Ledbrook <peter@...> wrote:
> > grails install-plugin > http://plugins.grails.org/grails-testing/trunk/grails-testing-0.3-SNAPSHOT.zip > That's what I did, yes. Works okay now. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released> That's what I did, yes. Works okay now.
Sorry, misunderstood what you said :) I just want to check one failing test I have and then I'll release 0.3 if that checks out. Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedQuickly following on, there is now a 0.3 release :)
* Fixes a bug in ControllerUnitTestCase * Supports "withFormat" in controllers * Basic support for testing tag libraries, through the new TagLibUnitTestCase The TagLibUnitTestCase adds an "out"property to the tag, which you can access and call toString() on to get the content written to the output writer. It also has support for the render tag - simply check the "renderArgs" property to find out whether it was called with the right arguments. Just thought, if you call "render" more than once in a tag, this won't work. For other tags, you will need to do something like: def tagLibControl = mockFor(MyTagLib) tagLibControl.demand.link(1..1) { ... } def tagLib = new MyTagLib() tagLib.myTag([:]) In other words, you'll have to mock the tag method calls. It supports the "g." prefix, but not custom namespaces yet. Any ideas welcome. Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: [ANN] Testing Plugin 0.2 sneakily releasedI've run into another problem with testing 0.3 - running tag lib unit
tests I get: No such property: redirectArgs for class: com.sky.entertainment.taglibs.AssetTagLib ... snip ... at grails.test.MvcUnitTestCase.newInstance(MvcUnitTestCase.groovy:72) --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: [ANN] Testing Plugin 0.2 sneakily released> I've run into another problem with testing 0.3 - running tag lib unit
> tests I get: > > No such property: redirectArgs for class: > com.sky.entertainment.taglibs.AssetTagLib > ... snip ... > at grails.test.MvcUnitTestCase.newInstance(MvcUnitTestCase.groovy:72) Ouch. I'm wondering, do you think there's any mileage in having those fields in MvcUnitTestCase, i.e. mockRequest, redirectArgs, etc.? I'm tempted to drop them completely so that the user retrieves them from the controller/tag library directly, i.e. assertEquals 10, controller.redirectArgs["count"] I think leaving the fields in there causes more problems than it solves. What do you think? I also need to fix "reset()" I think. Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Re: [ANN] Testing Plugin 0.2 sneakily releasedYeah, I'd have to say I prefer how that reads in the test.
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedHi,
I installed the 0.3 plugin; in my environment, the MockUtils.prepareForConstraintsTests() seems to have no effect, my validate() methods returns a Boolean rather than map of errors... my test code looks as follows: class CustomerDatasetTest extends grails.test.GrailsUnitTestCase { // Domain testing of Name attribute void testName() { // Mock the dynamic methods for CustomerDataset registerMetaClass(CustomerDataset) grails.test.MockUtils.prepareForConstraintsTests(CustomerDataset) // Negative test - no name def cds2 = new CustomerDataset() cds2.name = '' def errors = cds2.validate() assertEquals 1, errors.size() assertEquals "blank", errors["name"] } } The test code fails on line 17; errors.size() is failing because the variable errors is not a map with errors, butl a Boolean, just like the actual Domain method). The test script is placed in the app/test/unit directory. What am I missing? Thanks Edwin |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedHi Edwin,
Sorry, in the haste to get 0.2 and 0.3 out I think I missed mentioning a significant change. The validate() method does return a boolean now, just as it does "in the wild", i.e. when used in a running application. You need to access the errors object as you would in normal code: def cds2 = new CustomerDataset() cds2.name = '' cds2.validate() assertEquals 1, cds2.errors.errorCount assertEquals "blank", cds2.errors["name"] The "errors" object on the domain instance is now a proper Spring Errors instance, but we have overridden property access so that you can still use notation like "cds2.errors["name"]" and "cds2.errors.name". Hope that helps, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedHi Peter,
That did the trick; constraints testing with this plugin is a lot easier to write (getting close to the grammar simplicity of RoR unit testing)! I don't know the timeline for grails 1.1, but do you plan to release some more documentation for the plugin prior to bundling it with grails 1.1. Thanks, Edwin
|
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released> I don't know the timeline for grails 1.1, but do you plan to release some
> more documentation for the plugin prior to bundling it with grails 1.1. Yes. I'm planning (fingers crossed) to work on it this week. -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedPeter,
Does the constructor/properties based binding allow me to navigate hasMany associations, e.g. Domains: class Order { static hasMany = [orderLines : OrderLine] } class OrderLine { static belongsTo = [Order] Order parent } Test: class OrderTest extends grails.test.GrailsUnitTestCase { // Register metaclass, prepare... ..... // Create order and orderline def ord1 = new Order() def orderLine1 = new OrderLine(parent:ord1) // Navigate from order to order lines? assertNotNull ord1.orderLines } Q: can I navigate from order to order lines? On Tue, Sep 23, 2008 at 11:30 AM, Peter Ledbrook <peter@g2one.com> wrote: > Hi, > > I have released version 0.2 of the testing plugin. This doesn't > contain either the tag lib stuff or the URL mapping test classes, but > it does include: > > * A bunch of bug fixes > * getAll() static method for domain classes > * More render() implementations for controllers > * Support for mocking command objects > * Added constructor and ".properties" based data binding > * ".errors" on domain classes and command objects is a real "Errors" > instance > * save() method calls validate() and adds the new domain instance to > the list of test instances > * ".session" is now an implementation of HttpSession, not a map > > svn HEAD contains support for "withFormat" in controllers and it has > basic support for testing tag libraries. Not well tested yet though. > Now all I need is some time to document this stuff. > > Cheers, > > Peter > > -- > Software Engineer > G2One, Inc. > http://www.g2one.com/ > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily released2008/10/3 1 K Q06 <edwin.meijer@...>:
> > Peter, > > Does the constructor/properties based binding allow me to navigate hasMany > associations, e.g. > > Domains: > > class Order { > > static hasMany = [orderLines : OrderLine] > } > > class OrderLine { > static belongsTo = [Order] > Order parent > } > > Test: > > class OrderTest extends grails.test.GrailsUnitTestCase { > > // Register metaclass, prepare... > > ..... > > // Create order and orderline > > def ord1 = new Order() > def orderLine1 = new OrderLine(parent:ord1) > > > // Navigate from order to order lines? > > assertNotNull ord1.orderLines > > } > > Q: can I navigate from order to order lines? Only if you add the OrderLine to the "orderLines" property and you will have to initialise the property with a set. "new OrderLine(parent: ord1)" will not automatically add the OrderLine to the Order. Does that answer your question? Cheers, Peter -- Software Engineer G2One, Inc. http://www.g2one.com/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: [ANN] Testing Plugin 0.2 sneakily releasedDoes the testing plugin support custom (plugin) constraints?
I have adopted the phoneNumber plugin by Jim Shingler. I defined my domain as: class Contact { String phone phone(phoneNumber:true, blank:false, nullable:false) } Wrote a unit test using the testing 0.3 plugin: class MyTest extends grails.test.GrailsUnitTestCase { void testPhone() { registerMetaClass(Contact) grails.test.MockUtils.prepareForConstraintsTests(Contact) def cont1 = new Contact() cont1.phone = 'A231231234' // no characters allowed... cont1.validate() assertEquals 1, cont1.errors.errorCount assertEquals "phoneNumber", cont1.errors["phone"] } } This fails... it doesn't seem to invoke the custom phoneNumber constraint validator Then I wrote an old-style test: class MyTest extends GroovyTestCase { void testPhone() { def cont1 = new Contact() cont1.phone = 'not_a_number' cont1.validate() assertEquals 2, cont1.errors.errorCount TestHelper.assertFieldValidationError(cont1, 'phone', 'Contact.phone.phoneNumber.error.Contact.phone') } } Which works... What am I missing ? |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |