How to convert int to byte in unit testing DataRow?

264 Views Asked by At

I started making tests where i check bytes but i noticed that I can't write byte in DataRow, because I get a message: System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.Byte'.

How can I convert int to byte in DataRow?

[DataRow(12, 12)]
    [DataRow(23, 23)]
    public void Consturcot_1param(byte h, byte expectedH)
    {
        Time t = new Time(h);

        AssertTime(t, expectedH, expectedM: 0, expectedS: 0);
    }
1

There are 1 best solutions below

1
Peska On

The simplest solution would be to cast int to byte:

[DataRow((byte)12, (byte)12)]
[DataRow((byte)23, (byte)23)]
public void TestMethod(byte h, byte expectedH)
{ }