-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add simple Unit Tests #7542
Add simple Unit Tests #7542
Conversation
Hey @Davfon , great to see someone takes a look at our test suite! |
Hi there @calixtus ! Thanks for the quick feedback! I willl look into it and will try to convert them to parameterized tests wherever possible. |
@@ -151,4 +153,163 @@ public void parseCorrectlyByShortNameGermanLowercase() { | |||
assertEquals(Optional.of(Month.NOVEMBER), Month.parse("nov")); | |||
assertEquals(Optional.of(Month.DECEMBER), Month.parse("dez")); | |||
} | |||
|
|||
@Test | |||
public void parseGermanShortMonthTest() { |
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.
Is there more potential for parameterized tests here?
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.
Yes, there is. Thanks for the hint. I wasn't aware that you can also pass the expected result to the test.
Really nice feature :D
I changed all of them to parameterized Tests now.
|
||
@Test | ||
public void hashCodeTest() { | ||
assertEquals(Objects.hash(path, 10, 1, 4, "lineText"), citation.hashCode()); |
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.
Tests for Hashcode and toString do not really add any value and especially toString is more of an internal representation.
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.
Oh ok, seemed like a rather easy way to increase the code coverage. Thanks for letting me know, I'll try to avoid them in them in the future. (I removed them with commit 21050ff)
@@ -110,7 +110,7 @@ | |||
* @return the corresponding month instance, empty if input is not in German | |||
* form | |||
*/ | |||
private static Optional<Month> parseGermanShortMonth(String value) { | |||
public static Optional<Month> parseGermanShortMonth(String value) { |
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.
Maybe just remove the public prefix and make it "default"
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.
I'm not sure I understand it correctly, you mean like this: 5022f10?
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.
Yes, this makes it package visible, so it can be accessed by the unit test but not from others https://www.baeldung.com/java-access-modifiers
assertEquals(Collections.emptyList(), checker.check(entry)); | ||
} | ||
|
||
@Test | ||
void KeyFromAuthorAndTitle() { |
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.
I detect that this code is problematic. According to the Bad practice (BAD_PRACTICE), Nm: Method names should start with a lower case letter (NM_METHOD_NAMING_CONVENTION).
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
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.
Thanks for the feedback! Changed it in commit 93ab8a4
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.
Happy to help.
public void equalsTest() { | ||
Citation citation1 = new Citation(path, 10, 1, 4, "lineText"); | ||
Citation citation2 = null; | ||
assertTrue(citation.equals(citation1)); |
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.
This does not make any sense, why don't you use assertEquals? assertEquals calls the equals of the underlying objects. There is also a assertNotEquals method
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.
Yeah, that one is on me. Thanks for the feedback! :) Fixed in commit 6195973
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.
Just some minor issue, rest is okay
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.
Looks good to me too, thanks! Merging now.
* upstream/master: (191 commits) Fix for issue 7416: font size of the preferences dialog does not update with the rest of the GUI. (#7509) Fix school/instituation is printed twice (#7574) Dsiable notarisation until we hae an account for JabRef e.V. (#7572) Fix citation keys unintentionally being overwritten on import (#7443) Fix AuthentificationPlugin not declared in mergedModule (#7570) Suggestions for changes in caching latex free authors (#7301) Add simple Unit Tests (#7542) Fix drag and drop into empty library (#7555) Bump richtextfx from 0.10.4 to 0.10.6 (#7563) Bump pdfbox from 2.0.22 to 2.0.23 (#7561) Bump org.eclipse.jgit (#7560) Bump fontbox from 2.0.22 to 2.0.23 (#7562) Bump guava from 30.1-jre to 30.1.1-jre (#7564) Bump xmpbox from 2.0.22 to 2.0.23 (#7565) Bump hmarr/auto-approve-action from v2.0.0 to v2.1.0 (#7566) Add gource (#7193) UI: Fix for group icon (#7552) Fix for issue 6487: Opening BibTex file (doubleclick) from Folder with spaces not working (#7551) add ability to insert arxivId (#7549) Fixed missing trigger for linked file operations (#7548) ...
I have added some simple unit tests that will increase code coverage / branch coverage.
They contribute to issue #6207
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)