In general is it better to call methods such as fish.getX() or to directly access protected fields such as fish.x in tests? Thanks!
It’s better to use .getX() if it exists, but I wouldn’t make a “.getAppearance()” method solely to be referenced in a test, for example
Thanks! So are we supposed to test whether appearance changes as well?
No, that was just an example – strictly speaking, you just need to test that the listed behaviors work as they should, and none of the behaviors mention appearance.
Thanks!! Also, while we have to call setEntity() for any mocked objects, I am just wondering for the object that we are actually testing (ex. the main fish in FishTest), when should we call setEntity(x, y, fish)/getEntity(x, y) and when can we simply use setLocation(x, y)/getX()/getY()? Thank you!
If you are testing that a fish doesn’t collide with bubbles (this is a really important test!), you’ll need to add a bubble to the entities array (otherwise, how would the fish know where to look for it?)
In that case (e.g., collisions & seaweed eating), you’ll need to put mock entities in the actual grid so that they can be “discovered” by the entity you are actually testing
In the FollowingFish test, we didn’t need to add the “followee” into the entities array, because the following fish “learned” about it through its constructor – consider how this is different from collisions
So if the method that we are testing does not access the entities array, we can just use setLocation but it would still be okay if we use setEntity() in this case as well right?
I guess, just unnecessarily complicated