-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V2.0 Changes on PersonTest, ValidatorTest, UserControllerTest #13
base: master
Are you sure you want to change the base?
Conversation
rrecon
commented
Nov 2, 2019
- new Tests on PersonTest
- new Tests on validatortest
- not all tests finished in ValidatorTest
- Didn't get a solution for UserControllerTest
|
||
String fullName = p.getFullName(); | ||
|
||
Assertions.assertFalse(Boolean.parseBoolean(fullName), "Hannes Meier"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wieso machst du parseBoolean("1Hannes 2Meier")
?
Das zweite Argument "Hannes Meier" ist ja nur die Message welche angezeigt wird, wenn die Assertion fehlschlägt.
} | ||
|
||
@Test | ||
void getAge_ReturnsTrueWhenDifferentAge(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAge retourniert eine Zahl, die wird nie True sein.
void Person_TrueIf2ObjectsAreNotEqual(){ | ||
Person p = new Person("Hannes", "Meier", LocalDate.of(1940, 6, 30)); | ||
Person c = new Person("Petra", "Meier", LocalDate.of(1950, 3, 12)); | ||
Assertions.assertNotSame(p, c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertNotSame prüft nicht auf Equality, sondern Identity (im Testnamen redest du aber von Equality).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Krass viele tests hast du hier. Aber he! Wir müssen imfall nur die //TODO einträge lösen... streber 😂.
throw new IllegalArgumentException("you should implement code here"); | ||
db.addUser(user1); | ||
|
||
Assertions.assertTrue(UserValidator.isValidUsername(user2.getUsername()) && !UserValidator.doesUsernameExist(user2.getUsername())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Die inner static class heisst "doesUsernameExist", es ist also nicht nötig isValidUsername hier überhaupt aufzurufen, da du ja doesUsernameExist testen willst. Generell kann man sagen, dass es nicht empfohlen wird logische Verknüpfungen zu testen (ausser natürlich im Test geht es genau um darum ;)).
void returnsFalseIfUsernameNotInDBYet(){ | ||
throw new IllegalArgumentException("you should implement code here"); | ||
} | ||
void returnsTrueIfUsernameNotInDBYet(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unten prüfst du auf "assertTrue(!UserValidator.doesUsernameExist())", das ist ja genau das Gegenteil von "returnsTrue".
|
||
Assertions.assertTrue(UserValidator.isValidUsername(user2.getUsername()) && !UserValidator.doesUsernameExist(user2.getUsername())); | ||
//False if in DB | ||
Assertions.assertFalse(!UserValidator.doesUsernameExist(user1.getUsername())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wie im obigen Test reicht dieses zweite assert aus, da es genau das ist, was du im Testnamen angibst zu testen.
UserController test2 = new UserController(); | ||
|
||
Message message1 = new Message(); | ||
Method privateMessage = Message.class.getDeclaredMethod("Message", String.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Von welcher PowerPoint Folie oder Übung hast du denn das her :)?
I.d.R. kann man davon ausgehen, dass die vermittelten Kursinhalte ausreichen um die Übungen zu lösen (Hinweis: Im Testnamen steht gross MOCKITO :)).