by fpopa · 4y ago · 0 comments
Is it more similar to 'golden files'? Generate expected output and assert versus current implementation output?
1. I have a test for encryption/decryption functions. The data that's provided for the plaintext, additional data, and key, is generated. The assertions are:
assert_ne!(plaintext, encrypted_data);
assert_eq!(plaintext, decrypted_data);
assert_eq!(aad, decrypted_aad);
etc
2. I have some generated integration tests. For example, in our product, there are certain properties that should always hold for a given database entry. I generate a new entry on every test and have the fields for that entry provided by quickcheck, then I perform the operation, query the database, and assert that properties on those values hold.
So to answer your question, yes. Sometimes you want to check a concrete output (ie: "this base64 encoded string should always equal this other value) for sanity, but in general property tests give me more confidence.
I find it works particularly well with a 'given, when, then' approach, personally.
edit: I'll also note that for the base64 case I'd suggest:
a) A hardcoded suite of values.
b) Generate property tests.
assert_eq!(value, base64decode(base64encode(value));
As well as things like "contains only these characters" and "ends with [=a-zA-Z]" etc.
c) Oracle tests against a "known good" implementation.
We at https://symflower.com/ are working on a product to generate unit tests. Unlike quickcheck/proptest we promise to find errors, even if they are unlikely (for example [this input](https://github.com/AltSysrq/proptest/blob/master/proptest/RE...) would be trivial for Symflower). Also, unlike fuzzing our technology is deterministic.
Here's one of our blog posts that explains the approach: https://symflower.com/en/company/blog/2021/symflower-finds-m...
What does this actually mean, because I assume you didn't disprove Rice's theorem?