-
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
Yea :) #24
base: master
Are you sure you want to change the base?
Yea :) #24
Conversation
} | ||
|
||
// TODO some more useful tests | ||
// Other Test in the function on Top | ||
|
||
|
||
// --- getAge | ||
|
||
@Test | ||
void getAgeReturns10YearsIfBornIn2009() throws Exception { |
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.
Der Testinhalt stimmt nicht mit dem Testnamen überein :)
|
||
// TODO implement | ||
throw new IllegalArgumentException("you should implement code here"); | ||
Assertions.assertEquals(1, age.getDays()); |
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.
Was wenn age.getMonths() == 1 ... würde dein Test das bemerken?
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.
Sieht schon ganz gut aus! Einige Dinge hab ich trotzdem noch gefunden ;)
void returnsTrueIfSameNameInDBButWithDifferentLetterCasing() { | ||
// -> implement test | ||
/* ARRANGE */ | ||
UserValidator uv = new UserValidator(); |
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.
Damit dein Test wiederholbar und isoliert läuft müsstest du hier eine MockDatabase injecten.
void returnsTrueIfUsernameInDB__FAKE() { | ||
// -> implementiere / ergänze den Test hier, so dass dieser kompiliert und grün ist. | ||
/* ARRANGE */ | ||
FakeUserValidator uv = new FakeUserValidator(); |
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.
Deine SUT (getestete Klasse) sollte niemals ein Fake sein ;)
|
||
doReturn(true).when(uv).isValidUsername(anyString()); | ||
// eigentlich müsste untenstehende anweisung rein, ergibt jedoch einen error... keine ahnung wieso. | ||
//doReturn(true).when(uv).doesUsernameExist(anyString()); |
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.
Es wäre dann aber gemäss Testname "doReturn(false)" :). Was ist die Fehlermeldung?
User user = new User("kalua"); | ||
/* ACT */ | ||
Message result = uc.create(user); | ||
boolean result2 = uv.doesUsernameExist(user, db); |
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.
In allen Tests dieser Klasse ist das SUT der UserController.
Es ist also nicht nötig hier auf dem FakeUserValidator eine Methode aufzurufen. Du könntest aber prüfen ob db.getUsers() den gewünschten User retourniert.
/* ARRANGE */ | ||
UserValidator uv = mock(UserValidator.class); | ||
FileDatabase db = mock(FileDatabase.class); | ||
UserController uc = new UserController(uv, db); |
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.
Du solltest hier noch definieren was isValidUsername und doesUsernameExists retournieren sollen. Denn by default retournieren gemockte boolean Methoden ja false.
No description provided.