-
-
Notifications
You must be signed in to change notification settings - Fork 396
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
OBGM-328 Reference implementation for transaction type unit tests #4619
base: develop
Are you sure you want to change the base?
Conversation
} | ||
|
||
@Test | ||
void 'all fields validation'() { |
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.
what does the empty domain do here? What case is this testing?
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.
we are testing for empty domain. so it can throw error for all fields that has some validation. So in future if add any new field that can be catch 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.
Basically, so we can check all of the errors at once in case we accidentally added a nullable:false validation that isn't being tested elsewhere. This should also catch validation that was removed. We should make sure this test includes a check on the actual fields / error codes returned in the Errors object, not just the count.
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.
okay that makes sense. I like the idea. It forces you to consider tests when you make a schema change. Though I agree it's probably a good idea to at least assert on each of the errors instead of just the number of errors
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, that makes sense as you may have removed one validation rule and added another.
src/test/groovy/unit/org/pih/warehouse/inventory/TransactionTypeSpec.groovy
Outdated
Show resolved
Hide resolved
src/test/groovy/unit/org/pih/warehouse/inventory/TransactionTypeSpec.groovy
Outdated
Show resolved
Hide resolved
|
||
@Test | ||
@Unroll('TransactionType.validate() with name: #value should return #expected with errorCode: #expectedErrorCode') | ||
void 'name field validation'() { |
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.
What does the console output look like after running the tests if you do something like:
@Test
@Unroll
void 'TransactionType.validate() with name: #value should return #expected with errorCode: #expectedErrorCode'() {
...
}
If it's the same, then I'd prefer this format since it's redundant to need to specify the test name twice
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 would also like to see a more readable BDD expression for the test methods. Something like this would be infinitely more readable to me even if it's missing details like the target method. This also makes the test case easier to search.
Source: https://medium.com/version-1/spock-for-bdd-unit-testing-in-java-d67c2ddf25ad
void "Should return #expected with errorCode: #expectedErrorCode when name is #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.
@EWaterman I made some modifications to the tests and this is what the output looks like in the console.
and the test report
If we don't want data (especially long names) in the test spec description, then we could probably break the tests into "test with valid data" vs "tests against invalid data"
So, instead of this
org.pih.warehouse.inventory.TransactionTypeSpec > Should return false with error code nullable when validating transaction type given name null PASSED
org.pih.warehouse.inventory.TransactionTypeSpec > Should return false with error code maxSize.exceeded when validating transaction type given name aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa PASSED
org.pih.warehouse.inventory.TransactionTypeSpec > Should return true with error code null when validating transaction type given name bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb PASSED
we'd see this
org.pih.warehouse.inventory.TransactionTypeSpec > Should return false with error code nullable when validating transaction type given an invalid name PASSED
org.pih.warehouse.inventory.TransactionTypeSpec > Should return false with error code maxSize.exceeded when validating transaction type given an invalid name PASSED
org.pih.warehouse.inventory.TransactionTypeSpec > Should return true with error code null when validating transaction type given a valid name PASSED
Or we could add a test description to the table
adjective || value || expected | expectedErrorCode
null || null || false | 'nullable'
really long || 'a' * 256 || false | 'maxSize.exceeded'
longish || 'b' * 255 || true | null
valid || 'Dummy Name' || true | null
So the test spec
def 'Should return #expected with error code #expectedErrorCode when validating transaction type given a #adjective name'() {
would resolve to
org.pih.warehouse.inventory.TransactionTypeSpec > Should return false with error code maxSize.exceeded when validating transaction type given a really long PASSED
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 I agree in that I don't think we necessarily need to be ultra-verbose in specifying the exact inputs in the test name, but also I'm not sure if I'm a fan of needing to specify additional adjective fields just to populate the test name properly. I'm not sure it's the hugest deal either way. Ultimately I feel like as long as we stick to a general "X should return/do Y when Z" format, we're good.
src/test/groovy/unit/org/pih/warehouse/inventory/TransactionTypeSpec.groovy
Outdated
Show resolved
Hide resolved
…found any way to auto initialize these field from gorm. so initializing manually
These are final results after running test cases
|
} | ||
|
||
@Test | ||
@Unroll |
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.
You shouldn't need to add The Junit @Test
annotation because these are Spock tests.
Also, you don't need @Unroll
unless there's a where:
block
…uld not found any way to auto initialize these field from gorm. so initializing manually" This reverts commit 16be085
Unit test case for Transaction Type