• 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

compilation error in junit

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

i am trying to test my code using junit. i have created two classes -

1) business logic - Calculation.java
2) Test case - TestLogic.java.

inside the Calculation class, i have written the code for my business logic and in TestLogic class, i am actually testing my code of Calculation class.

the code of Calculation has been compiled successfully but i am getting error while compiling TestLogic class.

The error is "The method assertEquals(int, int) is undefined for the type TestLogic".

if i import its package like this "import static org.junit.Assert.*;", it is not allowing to do that.

it is showing me a compile time error as "Syntax error, static imports are only available if source level is 1.5".

please suggest me the appropriate solution for the same as i am beginner in junit.

i am using junit4-4.8.2 and java1.8 for this demo.

thanks and regards
Nishi Kishor
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First try changing the assert line to:


If it compiles, that means you aren't in fact pointing to Java 8. If it doesn't compile, that means JUnit isn't in your classpath. Please reply with which of the two it is and we can give you more direction in that space.
 
nishi kishor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This line "org.junit.Assert.assertEquals(1,1);" has been compiled successfully.
what should i do for the same.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So apparently you can't use static import (although you didn't say what error message you got). You're still using Java 1.4 then??!!! Java 5 was released over 10 years ago so you should really think about upgrading.

However if you can't do that because of institutional inertia or whatever then just do an ordinary import:



and then use the Assert class which you imported:

 
nishi kishor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
i am using java8 version and junit4 version in this program.
you can cross check it in the attachment.
the configuration for the demo project is shown in the attachment along with this post.
junit_javaVersion.jpeg
[Thumbnail for junit_javaVersion.jpeg]
screenshot for junit and java version
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nishi kishor wrote:
is showing me a compile time error as "Syntax error, static imports are only available if source level is 1.5".


Are you still getting this error or something else? You need to give the details of what you're seeing so people who would like to help don't have to keep guessing.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that's the error that you're seeing, then check your Java Compiler settings and make sure that the compatibility level setting is at least 1.5. Even if you have the Java 8 library configured, if you compile at a compatibility level that does not support static imports, you'll still get a compile-time error.
 
nishi kishor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys,
The issues has been resolved.
 
reply
    Bookmark Topic Watch Topic
  • New Topic