-
-
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
Refactoring and addition of unit tests #7581
Conversation
Added assertion explanation to give an explanatory message when the assertion fails.
Additionally removed the setup() method, since it was only used by a few test cases
Tests which exercise more than one production method are harder to read and understand, thus difficult to use as documentation. By splitting the two refactored tests into multiple ones, the readability has hugely increased.
small fix
… Eager Test) To not introduce another Test Smell (Sensitive Equality), I used the equals() method to compare the strings.
…Tests) Additionally removed the 'test' prefix in the naming as suggested in the 'Code Howtos' of the contribution guidelines.
…nsitive Equality) In addition, I removed the 'test' prefix in the namings as suggested in the contribution guidelines.
Added description for each assertion, which makes it easier to detect which one failed (in the case when the test itself fails)
Created new unit tests for each production method.
Increase of Line/Statement coverage
Increase of Line/Statement coverage
Increase of Line/Statement coverage
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.
Some comments, especially on using assertEquals(Optional.of(...), ...)
instead of assertTrue(...isPresent()
@Test | ||
public void sameAuthor() { | ||
String expectedAuthor = "Jaroslav Kucha ˇr"; | ||
assertTrue(annotationViewModel.getAuthor().equals(expectedAuthor)); |
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.
Why not assertEquals
? This is the usual way to check .equals
.
String expectedPage = "1"; | ||
assertTrue(annotationViewModel.getPage().equals(expectedPage)); |
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.
String expectedPage = "1"; | |
assertTrue(annotationViewModel.getPage().equals(expectedPage)); | |
assertEquals("1", annotationViewModel.getPage()); |
@Test | ||
public void retrieveCorrectDateAsString() { | ||
String expectedDate = "2017-07-20 10:11:30"; | ||
assertTrue(annotationViewModel.getDate().equals(expectedDate)); |
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.
Please create a one-liner like shown above.
@Test | ||
public void retrieveCorrectContent() { | ||
String expectedContent = "This is content"; | ||
assertTrue(annotationViewModel.getContent().equals(expectedContent)); |
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.
Please create a one-liner like shown above.
|
||
@Test | ||
void compareAuthorFieldBiggerAscending() 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.
No starting empty line please
private BibEntry entry1; | ||
private BibEntry entry2; | ||
|
||
@BeforeEach | ||
void setup() { | ||
entry1 = new BibEntry(); | ||
entry2 = new BibEntry(); | ||
} | ||
|
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.
private BibEntry entry1; | |
private BibEntry entry2; | |
@BeforeEach | |
void setup() { | |
entry1 = new BibEntry(); | |
entry2 = new BibEntry(); | |
} | |
private BibEntry entry1 = new BibEntry(); | |
private BibEntry entry2 = new BibEntry(); | |
} | ||
|
||
private EditionChecker createBibtexEditionChecker(Boolean bool) { |
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.
Please provide a speaking name for bool
BibEntry entry2 = new BibEntry(); | ||
entry2.setField(StandardField.OWNER, initialOwner); | ||
|
||
assertTrue(entry.getField(StandardField.OWNER).isPresent(), "Owner field for entry is not present"); |
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.
assertTrue(entry.getField(StandardField.OWNER).isPresent(), "Owner field for entry is not present"); | |
assertEquals(Optional.of(initialOwner), entry.getField(StandardField.OWNER)); |
Similar for all other Optional tests. We should avoid assertTrue
in all cases; we should use assertEquals
wherevery possible.
TimestampPreferences timestampPreferences = createTimestampPreference(); | ||
UpdateField.setAutomaticFields(bibs, false, ownerPreferences, timestampPreferences); | ||
|
||
assertEquals(entry.getField(StandardField.OWNER).get(), initialOwner, "entry has new value for owner field"); |
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.
assertEquals(entry.getField(StandardField.OWNER).get(), initialOwner, "entry has new value for owner field"); | |
assertEquals(Optional.of(initalOwner), entry.getField(StandardField.OWNER)); |
Was accidentally removed.
…Test also created one-liner as requested
Hi @koppor I finally adjusted the code accoring to your comments and suggestions :) |
public void testCreateTextBold() { | ||
String testText = "this is a test text"; | ||
public void stringRemainsTheSameAfterTransformationToNormal() { | ||
Text text = TooltipTextUtil.createText(testText, TooltipTextUtil.TextType.NORMAL); |
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.
Not addressed. Not that important, but this
String textStyle = "Regular";
assertEquals(textStyle, text.getFont().getStyle());
is IMHO less readable than
assertEquals("Regular", text.getFont().getStyle());
* upstream/main: (71 commits) [Bot] Update CSL styles (#7735) Fix for issue 6966: open all files of multiple entries (#7709) Add simple unit tests (#7696) Add simple unit tests (#7543) Update check-outdated-dependencies.yml Added preset for new entry keybindings and reintroduced defaults (#7705) Select the entry which has smaller dictonary order when merge (#7708) Update CHANGELOG.md fix: make more fields, fomatters, ids and languages sorted by alphabetical order (#7717) Bump libreoffice from 7.1.2 to 7.1.3 (#7721) Bump unoloader from 7.1.2 to 7.1.3 (#7724) Bump org.beryx.jlink from 2.23.7 to 2.23.8 (#7723) Bump org.openjfx.javafxplugin from 0.0.9 to 0.0.10 (#7725) fix: make fields sorted by lexicographical order (#7711) Fix tests Refactoring existing unit tests (#7687) Refactoring and addition of unit tests (#7581) Refactor simple Unit Tests (#7571) Add simple unit tests (#7544) add and extend unit tests (#7685) ...
This pull request includes new unit tests for three classes which increases their line/statement coverage.
They contribute to issue #6207.
Further, I have also refactored existing unit tests to make them more readable, understandable and maintanable.
In this sense, I focused more on test smells described in the paper Refactoring test code (van Deursen et al.) and also on the Code Howtos (Test Cases) in the Development Documentation.
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)