Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Hildreth
16,170 PointsNot sure what is wrong with my unit tests
Can someone please help me determine what is wrong with my unit tests? I seemed to have follow the video to the "T", but I am getting 3 tests failing. Why is this happening?
Here is my GitHub with my project in it: https://github.com/HanSolo0001/Unit-Testing
Here is the link to the video where I noticed the errors: https://teamtreehouse.com/library/green
1 Answer
Justin Kraft
26,327 PointsHello Daniel,
When I cloned your repository to my local workstation I noticed within Point.cs you did not override the Equals() and GetHashCode() methods in the base object class, therefore the object comparison in your tests were failing. They should be overridden similar to the code snippet shown below.
public override bool Equals(object obj) {
Point other = obj as Point;
if(other == null)
return false;
return X == other.X && Y == other.Y;
}
public override int GetHashCode() {
return X.GetHashCode() + Y.GetHashCode() * 31;
}
After adding the two methods to the Point class, the tests pass as expected.
Daniel Hildreth
16,170 PointsDaniel Hildreth
16,170 PointsActually, I noticed what's wrong with my code. I thought the final code download under the Teacher's Notes were where we were going to be coding along with Jeremy. However, that is not the case. Is there a copy and paste, or a download for all the code he added into the video? Or am I going to have to try and pause it and write it all out?
Edited: Ok, I noticed why his code was "different" than mine. He was in the Point class, whereas I was in the PointTest class. Silly mistake on my end, but fixed it.