Benefits are a clear separation of API structure tests and varying data, a reduction of the number of test methods, which leads to easier and more readable test classes. This also opens the possibility of introducing randomized testing (later).
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items
0
Link issues together to show that they're related.
Learn more.
I mostly agree that parameterized tests make the code more readable. However, there's one thing that makes them a bit less readable: without a test method name, whoever reads the code needs to guess why given test input produces given test output. That's not always obvious just by looking at the data.
As a (truly) random example, look at the various testSearchBase64* methods here. And now imagine how this would look like without test method names. Sure, it would be shorter. But would you still understand that the input data for testSearchBase64HashedFingerprintTorkaZ is the hashed fingerprint of one of the example relays? Stated differently, from looking at the data alone, would you be able to tell whether a given test case is already covered by existing tests or not?
I guess when we move to parameterized tests we should try to preserve the information that is currently contained in test method names. It could be in Java comments, though they might not be used or updated in practice. It could also be a String in yet another parameter (maybe first?) which might be printed out by JUnit in case of a failing test. Are there best practices for this issue, or how do others solve this?
Another potential problem is that, AFAIU, we'll have to split each (or at least most) of the current test classes into one or more that share parameters and another one that is non-parameterized. Should be okay, but we should ideally have a plan for this before moving around all existing unit test classes.
I mostly agree that parameterized tests make the code more readable. However, there's one thing that makes them a bit less readable: without a test method name, whoever reads the code needs to guess why given test input produces given test output. That's not always obvious just by looking at the data.
Well, the comments/descriptions can easily be added to the test data.
As a (truly) random example, look at the various testSearchBase64* methods here. And now imagine how this would look like without test method names. Sure, it would be shorter. But would you still understand that the input data for testSearchBase64HashedFingerprintTorkaZ is the hashed fingerprint of one of the example relays? Stated differently, from looking at the data alone, would you be able to tell whether a given test case is already covered by existing tests or not?
The methods names hint about the test's purpose, but are not really very helpful for the outside reader, being one word camel case.
I guess when we move to parameterized tests we should try to preserve the information that is currently contained in test method names. It could be in Java comments, though they might not be used or updated in practice. It could also be a String in yet another parameter (maybe first?) which might be printed out by JUnit in case of a failing test. Are there best practices for this issue, or how do others solve this?
(answered above, add the description string to the data)
Another potential problem is that, AFAIU, we'll have to split each (or at least most) of the current test classes into one or more that share parameters and another one that is non-parameterized. Should be okay, but we should ideally have a plan for this before moving around all existing unit test classes.
This is a valid point and will take some time structuring the changes. One immediate improvement would be adding a test description to the @Test annotation. These could be re-used later.