You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Christian Edward Gruber <cg...@google.com> on 2010/06/08 22:51:08 UTC

Component .java file unit testing and @Property

Hey,

     So @Property is beautiful, but sometimes when I'm testing the  
thin controller logic that remains I want access to an @Property from  
within the test in order to verify that something was done/changed.   
I've looked at PageTester, but I don't want to dig into the rendered  
document, because I'm really just testing the java logic.  But I also  
don't want to create accessors for my test objects alone.

     I've looked around and found PageTester, Testify, and tapestry- 
xpath, but nothing that I can run the component through that will add  
accessors/mutators for the @Property-annotated fields so my tests can  
access them.  I'm thinking something along the lines of:

     public void testFoo() {
         MyComponent foo = UnitTester.manifest(MyComponent.class);
         UnitTester.assign(foo, "bar", someBar);
         foo.doSomething();
         assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
     }

     ... where MyComponent.bar is a field with @Property.  There's  
really no need to create an accessor just for this, and certainly no  
need to render the component - I don't care about its rendering, just  
its code.

     Anything that might solve the problem this way?  Or any  
recommendations from Howard or others on where to start to build  
something like this myself?  I'm not very familiar with the  
classloader stuff we do in T5 and the javassist work... if I am going  
to do this myself, I'll need some good hints as to where to start  
looking.

cheers,
Christian.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Component .java file unit testing and @Property

Posted by Christian Edward Gruber <cg...@google.com>.
Ok, so I ran into an issue where, because of how the TestUtil class  
fits in the hierarchy of TestBase, etc, it requires a dependency on  
org.testng.Assert.

I filed a bug in JIRA and added a patch to extract PropertyUtil, but  
maintaining the TestUtil signatures for backwards compatibility, but  
the PropertyUtil should work just fine without TestNG on the classpath.

https://issues.apache.org/jira/browse/TAP5-1183

Would someone mind taking a peek at that - other than, perhaps, some  
headers stuff in the new file, I think it's pretty straightforward.

cheers,
Christian.

On Jun 8, 2010, at 5:03 PM, Igor Drobiazko wrote:

> Please have a look at TestUtils [1]. Methods create(), set() and  
> get() are
> what you are looking for. For T5.1 see [2].
>
> [1]
> http://tapestry.apache.org/tapestry5.2-dev/apidocs/org/apache/tapestry5/ioc/test/TestUtils.html
> [2]
> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/test/TestBase.html
>
> On Tue, Jun 8, 2010 at 10:51 PM, Christian Edward Gruber <cgruber@google.com
>> wrote:
>
>> Hey,
>>
>>   So @Property is beautiful, but sometimes when I'm testing the thin
>> controller logic that remains I want access to an @Property from  
>> within the
>> test in order to verify that something was done/changed.  I've  
>> looked at
>> PageTester, but I don't want to dig into the rendered document,  
>> because I'm
>> really just testing the java logic.  But I also don't want to create
>> accessors for my test objects alone.
>>
>>   I've looked around and found PageTester, Testify, and tapestry- 
>> xpath,
>> but nothing that I can run the component through that will add
>> accessors/mutators for the @Property-annotated fields so my tests  
>> can access
>> them.  I'm thinking something along the lines of:
>>
>>   public void testFoo() {
>>       MyComponent foo = UnitTester.manifest(MyComponent.class);
>>       UnitTester.assign(foo, "bar", someBar);
>>       foo.doSomething();
>>       assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
>>   }
>>
>>   ... where MyComponent.bar is a field with @Property.  There's  
>> really no
>> need to create an accessor just for this, and certainly no need to  
>> render
>> the component - I don't care about its rendering, just its code.
>>
>>   Anything that might solve the problem this way?  Or any  
>> recommendations
>> from Howard or others on where to start to build something like  
>> this myself?
>> I'm not very familiar with the classloader stuff we do in T5 and the
>> javassist work... if I am going to do this myself, I'll need some  
>> good hints
>> as to where to start looking.
>>
>> cheers,
>> Christian.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> -- 
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de/blog


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Component .java file unit testing and @Property

Posted by Christian Edward Gruber <ch...@gmail.com>.
Woot!  Thanks.  I thought I'd read about these, but couldn't find  
them.  We'll check them out.  Saves some effort on my part.  Let's get  
those into the page on unit testing. I only saw PageTester. :)

Christian.

On Jun 8, 2010, at 5:03 PM, Igor Drobiazko wrote:

> Please have a look at TestUtils [1]. Methods create(), set() and  
> get() are
> what you are looking for. For T5.1 see [2].
>
> [1]
> http://tapestry.apache.org/tapestry5.2-dev/apidocs/org/apache/tapestry5/ioc/test/TestUtils.html
> [2]
> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/test/TestBase.html
>
> On Tue, Jun 8, 2010 at 10:51 PM, Christian Edward Gruber <cgruber@google.com
>> wrote:
>
>> Hey,
>>
>>   So @Property is beautiful, but sometimes when I'm testing the thin
>> controller logic that remains I want access to an @Property from  
>> within the
>> test in order to verify that something was done/changed.  I've  
>> looked at
>> PageTester, but I don't want to dig into the rendered document,  
>> because I'm
>> really just testing the java logic.  But I also don't want to create
>> accessors for my test objects alone.
>>
>>   I've looked around and found PageTester, Testify, and tapestry- 
>> xpath,
>> but nothing that I can run the component through that will add
>> accessors/mutators for the @Property-annotated fields so my tests  
>> can access
>> them.  I'm thinking something along the lines of:
>>
>>   public void testFoo() {
>>       MyComponent foo = UnitTester.manifest(MyComponent.class);
>>       UnitTester.assign(foo, "bar", someBar);
>>       foo.doSomething();
>>       assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
>>   }
>>
>>   ... where MyComponent.bar is a field with @Property.  There's  
>> really no
>> need to create an accessor just for this, and certainly no need to  
>> render
>> the component - I don't care about its rendering, just its code.
>>
>>   Anything that might solve the problem this way?  Or any  
>> recommendations
>> from Howard or others on where to start to build something like  
>> this myself?
>> I'm not very familiar with the classloader stuff we do in T5 and the
>> javassist work... if I am going to do this myself, I'll need some  
>> good hints
>> as to where to start looking.
>>
>> cheers,
>> Christian.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> -- 
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de/blog


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Component .java file unit testing and @Property

Posted by Igor Drobiazko <ig...@gmail.com>.
Please have a look at TestUtils [1]. Methods create(), set() and get() are
what you are looking for. For T5.1 see [2].

[1]
http://tapestry.apache.org/tapestry5.2-dev/apidocs/org/apache/tapestry5/ioc/test/TestUtils.html
[2]
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/test/TestBase.html

On Tue, Jun 8, 2010 at 10:51 PM, Christian Edward Gruber <cgruber@google.com
> wrote:

> Hey,
>
>    So @Property is beautiful, but sometimes when I'm testing the thin
> controller logic that remains I want access to an @Property from within the
> test in order to verify that something was done/changed.  I've looked at
> PageTester, but I don't want to dig into the rendered document, because I'm
> really just testing the java logic.  But I also don't want to create
> accessors for my test objects alone.
>
>    I've looked around and found PageTester, Testify, and tapestry-xpath,
> but nothing that I can run the component through that will add
> accessors/mutators for the @Property-annotated fields so my tests can access
> them.  I'm thinking something along the lines of:
>
>    public void testFoo() {
>        MyComponent foo = UnitTester.manifest(MyComponent.class);
>        UnitTester.assign(foo, "bar", someBar);
>        foo.doSomething();
>        assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
>    }
>
>    ... where MyComponent.bar is a field with @Property.  There's really no
> need to create an accessor just for this, and certainly no need to render
> the component - I don't care about its rendering, just its code.
>
>    Anything that might solve the problem this way?  Or any recommendations
> from Howard or others on where to start to build something like this myself?
>  I'm not very familiar with the classloader stuff we do in T5 and the
> javassist work... if I am going to do this myself, I'll need some good hints
> as to where to start looking.
>
> cheers,
> Christian.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de/blog

Re: Component .java file unit testing and @Property

Posted by Christian Edward Gruber <ch...@gmail.com>.
I encountered this and use TestUtil (TestUtils?) to extract and set  
properties without creating accessors/mutators.   Makes the test read  
a little less "O-O" but it's perfectly serviceable.

My only issue was that TestUtils is part of the tapestry convenience  
test case hierarchy which depends on TestNG, so I pulled apart the  
methods in question into a PropUtils which we use internally.  I have  
a patch in to do this in trunk/ and a bug filed.

cheers,
Christian.

On Jun 17, 2010, at 3:26 PM, Peter Niederwieser wrote:

>
> Another option: Write your tests in Groovy, which lets you access  
> private
> fields. (Of course you'll get other benefits from using Groovy. In  
> short,
> it's a much better language for testing, especially when combined with
> Spock.)
>
> Cheers,
> Peter
>
>
> Christian Edward Gruber-3 wrote:
>>
>> Hey,
>>
>>     So @Property is beautiful, but sometimes when I'm testing the
>> thin controller logic that remains I want access to an @Property from
>> within the test in order to verify that something was done/changed.
>> I've looked at PageTester, but I don't want to dig into the rendered
>> document, because I'm really just testing the java logic.  But I also
>> don't want to create accessors for my test objects alone.
>>
>>     I've looked around and found PageTester, Testify, and tapestry-
>> xpath, but nothing that I can run the component through that will add
>> accessors/mutators for the @Property-annotated fields so my tests can
>> access them.  I'm thinking something along the lines of:
>>
>>     public void testFoo() {
>>         MyComponent foo = UnitTester.manifest(MyComponent.class);
>>         UnitTester.assign(foo, "bar", someBar);
>>         foo.doSomething();
>>         assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
>>     }
>>
>>     ... where MyComponent.bar is a field with @Property.  There's
>> really no need to create an accessor just for this, and certainly no
>> need to render the component - I don't care about its rendering, just
>> its code.
>>
>>     Anything that might solve the problem this way?  Or any
>> recommendations from Howard or others on where to start to build
>> something like this myself?  I'm not very familiar with the
>> classloader stuff we do in T5 and the javassist work... if I am going
>> to do this myself, I'll need some good hints as to where to start
>> looking.
>>
>> cheers,
>> Christian.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>
> -- 
> View this message in context: http://old.nabble.com/Component-.java-file-unit-testing-and-%40Property-tp28823028p28918663.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Component .java file unit testing and @Property

Posted by Peter Niederwieser <pn...@gmail.com>.
Another option: Write your tests in Groovy, which lets you access private
fields. (Of course you'll get other benefits from using Groovy. In short,
it's a much better language for testing, especially when combined with
Spock.)

Cheers,
Peter


Christian Edward Gruber-3 wrote:
> 
> Hey,
> 
>      So @Property is beautiful, but sometimes when I'm testing the  
> thin controller logic that remains I want access to an @Property from  
> within the test in order to verify that something was done/changed.   
> I've looked at PageTester, but I don't want to dig into the rendered  
> document, because I'm really just testing the java logic.  But I also  
> don't want to create accessors for my test objects alone.
> 
>      I've looked around and found PageTester, Testify, and tapestry- 
> xpath, but nothing that I can run the component through that will add  
> accessors/mutators for the @Property-annotated fields so my tests can  
> access them.  I'm thinking something along the lines of:
> 
>      public void testFoo() {
>          MyComponent foo = UnitTester.manifest(MyComponent.class);
>          UnitTester.assign(foo, "bar", someBar);
>          foo.doSomething();
>          assertEquals(anotherBar, UnitTester.obtain(foo, "bar"));
>      }
> 
>      ... where MyComponent.bar is a field with @Property.  There's  
> really no need to create an accessor just for this, and certainly no  
> need to render the component - I don't care about its rendering, just  
> its code.
> 
>      Anything that might solve the problem this way?  Or any  
> recommendations from Howard or others on where to start to build  
> something like this myself?  I'm not very familiar with the  
> classloader stuff we do in T5 and the javassist work... if I am going  
> to do this myself, I'll need some good hints as to where to start  
> looking.
> 
> cheers,
> Christian.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Component-.java-file-unit-testing-and-%40Property-tp28823028p28918663.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org