-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Write tests with more than 80% coverage #834
base: main
Are you sure you want to change the base?
Conversation
Fixes for Java CI tests
Fixes for Java CI tests
|
||
@Test | ||
void listOperationsFromCsv_validText_ok() { | ||
List<String> inputList = List.of("b,banana,20", "b,apple,100"); |
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 think it's better to create String of operation before each method or like constant, and use in each testMethods and in that way avoid code duplication
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, I think it's a good point
balanceOperation = new GoodsOperation(balanceOperation.getTransactionType(), | ||
null, | ||
balanceOperation.getQuantity()); | ||
Assertions.assertThrows(RuntimeException.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.
It's better to throw more specific exception or check exception message like example bellow:
@test
public void whenExceptionThrown_thenAssertionSucceeds() {
Exception exception = assertThrows(NumberFormatException.class, () -> {
Integer.parseInt("1a");
});
String expectedMessage = "For input string";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
}
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.
Cool advice! Thank you!
purchaseOperation = new GoodsOperation(purchaseOperation.getTransactionType(), | ||
null, | ||
purchaseOperation.getQuantity()); | ||
Assertions.assertThrows(RuntimeException.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.
It's better to throw more specific exception or check exception message
returnOperation = new GoodsOperation(returnOperation.getTransactionType(), | ||
null, | ||
returnOperation.getQuantity()); | ||
Assertions.assertThrows(RuntimeException.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.
It's better to throw more specific exception or check exception message
supplyOperation = new GoodsOperation(supplyOperation.getTransactionType(), | ||
null, | ||
supplyOperation.getQuantity()); | ||
Assertions.assertThrows(RuntimeException.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.
It's better to throw more specific exception or check exception message
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.
Good job, consider some points to improve
@AfterEach | ||
void tearDown() { | ||
} |
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 wondering if we really need that one if it does nothing?
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.
Forgot to remove it...
for (int i = 0; i < actual.size(); i++) { | ||
Assertions.assertEquals(expected.get(i), actual.get(i)); | ||
} |
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.
for (int i = 0; i < actual.size(); i++) { | |
Assertions.assertEquals(expected.get(i), actual.get(i)); | |
} | |
assertIterableEquals(expected, actual); |
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.
Cool advice! Thank you!
for (int i = 0; i < expectedList.size(); i++) { | ||
Assertions.assertEquals(expectedList.get(i), actualList.get(i)); | ||
} |
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.
for (int i = 0; i < expectedList.size(); i++) { | |
Assertions.assertEquals(expectedList.get(i), actualList.get(i)); | |
} | |
assertIterableEquals(expectedList, actualList); |
for (int i = 0; i < actualList.size(); i++) { | ||
Assertions.assertEquals(expectedList.get(i), actualList.get(i)); | ||
} |
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.
for (int i = 0; i < actualList.size(); i++) { | |
Assertions.assertEquals(expectedList.get(i), actualList.get(i)); | |
} | |
assertIterableEquals(expectedList, actualList); |
for (int i = 0; i < actualList.size(); i++) { | ||
Assertions.assertEquals(expectedsList.get(i), actualList.get(i)); | ||
} |
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.
for (int i = 0; i < actualList.size(); i++) { | |
Assertions.assertEquals(expectedsList.get(i), actualList.get(i)); | |
} | |
assertIterableEquals(expectedsList, actualList); |
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.
Good job!
No description provided.