| Author |
[JUnit 4, Ant 1.7] assertEquals et assertTrue undefined
|
Celinio Fernandes
Ranch Hand
Joined: Jun 28, 2003
Posts: 546
|
|
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.
|
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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.*;
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Celinio Fernandes
Ranch Hand
Joined: Jun 28, 2003
Posts: 546
|
|
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
Joined: Jul 11, 2001
Posts: 14112
|
|
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?
|
 |
 |
|
|
subject: [JUnit 4, Ant 1.7] assertEquals et assertTrue undefined
|
|
|