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

howto test "assert" in eclipse ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, good day , do anyone know how to test the assert function on eclipse IDE ?

let say i hv following code to test how assert to work



when i run the IDE , give me the error like "assert should not use for identifier" and also "the method assert(boolean) is undefined" ...anyone can guide how i test it ? thank you
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set the project up for J2SDK 1.4 or greater. The default is 1.3, which predates the addition of assertions.

If you select the project properties dialog, click on the "Java Compiler" topic and then select the "Compiler compliance" tab, you'll see options. You need to pick 1.4 or greater for both source and class file compatibility.

Note that this doesn't affect Ant Scripts, where you have to add the 'source="1.4"' option on the javac task or the interactive Java compiler in Eclipse will handle asserts properly (assuming you did the above) but batch compiles using your Ant file (if present) won't.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you , tim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic