Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[JUnit 4, Ant 1.7] assertEquals et assertTrue undefined

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
my environment:
Junit 4.0
Ant 1.7
Eclipse 3.3
Java 1.5

I am trying to run a JUnit test with Eclipse 3.3 (Europa) but I have a small compilation problem:

==>
The method assertEquals(int, int) is undefined for the type PersonTest
and
The method assertTrue(boolean) is undefined for the type PersonTest

If I import junit.framework.TestCase and extend TestCase :

then it compiles but then I am not using JUnit 4.
And anyways the test fails because it complains that it does not find test methods ...

Is there a compatibility problem in the versions I use ?
(with ant, eclipse, junit ...)

Thanks in advance for your help.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a junit 3 test, you need to configure the launch configuration.

For junit 4, simply statically import the assert methods:

import static org.junit.Assert.*;
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that works.
I was not aware of this new feature of JS2E 1.5
Static imports seem a bit inappropriate to me, i am not sure this is a good thing.
It can make the code less readable, for example it is harder to see in which class a constant is defined, especially with the use of the wildcard in static imports, also called en masse imports.
[ December 30, 2007: Message edited by: Celinio Fernandes ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Celinio Fernandes:
Static imports seem a bit inappropriate to me, i am not sure this is a good thing.
It can make the code less readable, for example it is harder to see in which class a constant is defined, especially with the use of the wildcard in static imports, also called en masse imports.


Not harder than with implementing an interface where the constant is defined, which was common practice before Java 5 - and which was arguably even more inappropriate.

I find it to be a convenient feature, although it certainly can be misused. Which feature can't?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic