mardi 26 septembre 2017

Unit testing a void method in an internal static class

How do we go about testing a void method without instantiating the object in the test class? I understand in an internal static class we are unable to use "new" to create an object to test it. I've unit tested by creating objects for non static class but I haven't dealt with an internal static class and am stuck. Any guidance would be great.

Here is the class/method in question:

internal static class Util
{
    public static void AssertBytesEqual(byte[] expected, byte[] actual)
    {
        if (expected.Length != actual.Length)
        {
            Debugger.Break();
            throw new CryptographicException("The bytes were not of the expected length.");
        }

        for (int i = 0; i < expected.Length; i++)
        {
            if (expected[i] != actual[i])
            {
                Debugger.Break();
                throw new CryptographicException("The bytes were not identical.");
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire