You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Steve Loughran <st...@apache.org> on 2007/10/29 17:48:04 UTC

getting const strings into antunit tests

Now, one more feature for someone to add, which is a variant of what we 
added to smartfrog last week.

1. In junit tests, you can reference the Java string in the java code, 
so your tests dont break if the message changes.

2. If you test in a higher level framework (antunit, sf test compounds), 
you cant do that, so you copy and paste the string in.

3. which is very brittle.

Our solution was to add a new reference, so we can extract text from a 
java static member

testBadHost extends SSHTestExpectsFailure {
	
	action:host="missing.example.org";

	expectedText CONSTANT "org.smartfrog.services.ssh.sshExec.ERROR_NO_HOST";

}


you end up being immune to string changes, only to moved constants and 
people moving to fancy formatted strings.

seems to me, we could do the same with an ant resource, one that returns 
the toString value of a resource as its contents. then we enhance 
antunit to have a <resourceeuqals> assertion that compares two resources 
(we have something like this, right?), and we can just search for the 
specific resource in text, error logs,etc.



-- 
Steve Loughran                  http://www.1060.org/blogxter/publish/5
Author: Ant in Action           http://antbook.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: getting const strings into antunit tests

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 30 Oct 2007, Dominique Devienne <dd...@gmail.com> wrote:
> On 10/30/07, Stefan Bodewig <bo...@apache.org> wrote:
>> On Mon, 29 Oct 2007, Steve Loughran <st...@apache.org> wrote:
>> > Our solution was to add a new reference, so we can extract text
>> > from a java static member [...]  seems to me, we could do the
>> > same with an ant resource,
>>
>> <property name="expected" javaConstant="..."/>
>> I think it would feel more natural in property.
> 
> But then someone will want to be able to specify the classpath used
> to lookup the class, so we had a nested <classpath> to
> <property>?.

That is already there (for resource="...") ;-)

> I thought we shied away from overloading <property> anymore?

True.  I can just imagine more cases where I'd want the value of a
constant in something I can expand via ${} than in a resource.

Of course we can go from one to the other with either a <string>
resource (property -> resource) or <loadresource> (resource ->
property) so it is not too important.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: getting const strings into antunit tests

Posted by Steve Loughran <st...@apache.org>.
Dominique Devienne wrote:
> On 10/30/07, Stefan Bodewig <bo...@apache.org> wrote:
>> On Mon, 29 Oct 2007, Steve Loughran <st...@apache.org> wrote:
>>> Our solution was to add a new reference, so we can extract text from
>>> a java static member [...]
>>> seems to me, we could do the same with an ant resource,
>> <property name="expected" javaConstant="..."/>
>> I think it would feel more natural in property.
> 
> But then someone will want to be able to specify the classpath used to
> lookup the class, so we had a nested <classpath> to <property>?. I
> thought we shied away from overloading <property> anymore? Just
> playing devil's advocate I guess. --DD
> 

More to the point, if we have a resource that provides a string, it 
plugs in anywhere that resources get used. It fits in very well with the 
resource-centric world view, and if we already have the resource 
comparison tests, then it slides in very easily indeed.

-steve

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: getting const strings into antunit tests

Posted by Dominique Devienne <dd...@gmail.com>.
On 10/30/07, Stefan Bodewig <bo...@apache.org> wrote:
> On Mon, 29 Oct 2007, Steve Loughran <st...@apache.org> wrote:
> > Our solution was to add a new reference, so we can extract text from
> > a java static member [...]
> > seems to me, we could do the same with an ant resource,
>
> <property name="expected" javaConstant="..."/>
> I think it would feel more natural in property.

But then someone will want to be able to specify the classpath used to
lookup the class, so we had a nested <classpath> to <property>?. I
thought we shied away from overloading <property> anymore? Just
playing devil's advocate I guess. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: getting const strings into antunit tests

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 29 Oct 2007, Steve Loughran <st...@apache.org> wrote:


> Our solution was to add a new reference, so we can extract text from
> a java static member
> 
> testBadHost extends SSHTestExpectsFailure {
> 	
> 	action:host="missing.example.org";
> 
> 	expectedText CONSTANT
> 	"org.smartfrog.services.ssh.sshExec.ERROR_NO_HOST";
> 
> }
> 
> 
> you end up being immune to string changes, only to moved constants
> and people moving to fancy formatted strings.
> 
> seems to me, we could do the same with an ant resource,

Or with properties.

<property name="expected" javaConstant="..."/>

I think it would feel more natural in property.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: getting const strings into antunit tests

Posted by Matt Benson <gu...@yahoo.com>.
--- Steve Loughran <st...@apache.org> wrote:

> 
> Now, one more feature for someone to add, which is a
> variant of what we 
> added to smartfrog last week.
> 
> 1. In junit tests, you can reference the Java string
> in the java code, 
> so your tests dont break if the message changes.
> 
> 2. If you test in a higher level framework (antunit,
> sf test compounds), 
> you cant do that, so you copy and paste the string
> in.
> 
> 3. which is very brittle.
> 
> Our solution was to add a new reference, so we can
> extract text from a 
> java static member
> 
> testBadHost extends SSHTestExpectsFailure {
> 	
> 	action:host="missing.example.org";
> 
> 	expectedText CONSTANT
> "org.smartfrog.services.ssh.sshExec.ERROR_NO_HOST";
> 
> }
> 
> 
> you end up being immune to string changes, only to
> moved constants and 
> people moving to fancy formatted strings.
> 
> seems to me, we could do the same with an ant
> resource, one that returns 
> the toString value of a resource as its contents.

toString value of a resource?  Or were you trying to
say a "constant" resource would basically be the
toString of some constant (i.e. public static final
member), usually a String itself?

> then we enhance 
> antunit to have a <resourceeuqals> assertion that
> compares two resources 
> (we have something like this, right?), and we can
> just search for the 
> specific resource in text, error logs,etc.
> 

We have a resourcesmatch condition; we could certainly
complement with a resourcecontains condition or some
such.  Would that suffice?

-Matt

> 
> 
> -- 
> Steve Loughran                 
> http://www.1060.org/blogxter/publish/5
> Author: Ant in Action           http://antbook.org/
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org