I have implemented a very simple class called Enigma
which has a symmetric key and two methods: byte[] encryptString(String strToEncrypt)
and String decryptBytes(byte[] arrayToDecrypt)
.
I am trying to write some tests for the methods. I have thought of testing that the encrypt and decrypt methods are the inverse of each other, but that says nothing about each of them individually. I wanted to use the methods as they are now to obtain a battery of input-outputs and set that as the tests (I know that is not ideal, but the purpose of these tests is to guarantee that the function behaves in the future as it does today, not that the encryption/decryption are good).
However, I do not know how to obtain a representation of the byte array output by byte[] encryptString(String strToEncrypt)
so that I can hardcode it in the test class.
Any ideas?
A few notes on how to test this ( personal opinion warning :-) )
My last point there brings me (finally ?) to a recommendation. Think about what's the responsibility of the class (hopefully, the single responsibility, see SRP). In this case, I believe that the responsibility of your class is two way encryption of strings.
Therefore, I would write the following tests:
Maybe add some more tests to check that trying to encrypt/decrypt invalid values throws exceptions, and other error cases.