Friday, 19 June 2015

Junit Error: assertEquals() method undefined for the type

There are 2 ways to fix this error depending on the junit version you are using.

1. If you are using Junit 4.X,  you need to have the following import statement 
    import static org.unit.Assert.* 

   This Assert class contains the set of assertion methods useful for writing tests. 
   For ex it has assertArrayEquals(), assertEquals(), assertFalse(), assertTrue() etc. 

   All these static methods can be referenced with out prefix in the code.

   Please refer to the below link for more info on static class.


2. If you are using Junit 3.X , you need to import junit.framework.TestCase and your
    test class should extend the TestCase. By extending the junit.framework.TestCase,

    It inherits junit.framework.Assert default and your test class will have the access
    to the Assertion methods.

2 comments:

  1. I know you posted this a while ago, but this is exactly what I needed. Thank you!

    ReplyDelete
  2. Hey there, or perhaps might be away from issue rather regardless, i surfing surrounding your internet-site also seems essentially truly professional. I’m also creating a new-found blogging site because trying to cope to create it bode well, each i’ve addition few things since i mess it up. In which way painful was first the site to develop your site? May perhaps one as i am without the suffer from do it right, to fit cherished ones modify documents without having to wrecking the application training? trendsvrends.co

    ReplyDelete