• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[JUnit 4, Ant 1.7] assertEquals et assertTrue undefined

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic