Sir Celsius
Sir Celsius

Reputation: 872

Grails Unit Testing Extends

You can find a sample app that recreates the problem on github

I created an app with two domains: Abstract and Extends. As their names state, the first one is abstract, and the second one extends the first one.

I am trying to test an ExtendsController method that calls Abstract.list(). In my test class, I have created three instances of Extends names extends1, extends2 and extends3.

I would expect my method to return [extend1, extend2, extend3], so I'm testing it with

assert controller.list() == `[extend1, extend2, extend3]

However, the test fails with the following output:

assert controller.list() == [extend1, extend2, extend3]
       |          |      |   |        |        |
       |          |      |   |        |        com.test.Extend : 3
       |          |      |   |        com.test.Extend : 2
       |          |      |   com.test.Extend : 1
       |          |      false
       |          [com.test.Extend : 1, com.test.Extend : 2, com.test.Extend : 3]
       com.test.ExtendController@61d66115

Why does it fail? How do I fix it?

I'm using grails 2.2.4

Edit

I'm aware that this will create a database table for my Abstract class, that is the behavior I'm expecting.

Upvotes: 0

Views: 30

Answers (1)

Marcin Świerczyński
Marcin Świerczyński

Reputation: 2322

Try to overwrite equals method in Extend class. Otherwise, the comparison will return false, because technically the objects are different.

Upvotes: 1

Related Questions