New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCaseSource unable to pass one element byte array #1851

Closed
m-wilczynski opened this Issue Oct 18, 2016 · 5 comments

Comments

Projects
None yet
7 participants
@m-wilczynski
Contributor

m-wilczynski commented Oct 18, 2016

NUnit version: 3.5.0
Runner: NUnit3TestAdapter 3.4.1
Environment: Visual Studio 2015 Pro Update 1

I'm having troubles using one element byte array passed to NUnit test with TestCaseSourceAttribute.

How to reproduce:

public class Test
    {
        private static List<byte[]> _byteArrays = new List<byte[]>
        {
            new byte[] { 80 }, // - works fine with commented out
            new byte[] { 80, 75 },
            new byte[] { 80, 75, 03 }
        };

        [Test]
        [TestCaseSource("_byteArrays")]
        public void TestStuff(byte[] byteArray)
        {
            Assert.IsFalse(false);
        }
    }

When you run TestStuff it will attempt to test things in seperate tests like this:

nunit

It clearly seems that first element is treated as an System.Byte instead of System.Byte[].

Error produced by NUnit tells it clearly:

Result Message:System.ArgumentException : Object of type 'System.Byte' cannot be converted to type 'System.Byte[]'

Any ideas on fixing this?
Thanks!

@rprouse

This comment has been minimized.

Show comment
Hide comment
@rprouse

rprouse Oct 18, 2016

Member

This was reported in #1327 and was supposed to have been fixed in PR #1354, but I can confirm that this is still happening using v3.5 of the framework and the console runner.

As a temporary workaround, you can change your source to

private static IEnumerable _byteArrays = new object[]
{
    new TestCaseData(new byte[] { 80 }), // - works fine with commented out
    new byte[] { 80, 75 },
    new byte[] { 80, 75, 03 }
};

Thanks for the report.

Member

rprouse commented Oct 18, 2016

This was reported in #1327 and was supposed to have been fixed in PR #1354, but I can confirm that this is still happening using v3.5 of the framework and the console runner.

As a temporary workaround, you can change your source to

private static IEnumerable _byteArrays = new object[]
{
    new TestCaseData(new byte[] { 80 }), // - works fine with commented out
    new byte[] { 80, 75 },
    new byte[] { 80, 75, 03 }
};

Thanks for the report.

@gcichosz

This comment has been minimized.

Show comment
Hide comment
@gcichosz

gcichosz Mar 1, 2017

Contributor

Can I grab this issue?

Contributor

gcichosz commented Mar 1, 2017

Can I grab this issue?

@CharliePoole

This comment has been minimized.

Show comment
Hide comment
@CharliePoole

CharliePoole Mar 1, 2017

Member

@gcichosz I assigned it to you.

It's a tricky issue. I suggest first ensuring we have sufficient tests to cover all the cases that may arise.

Basically, this problem comes up with all array types. In this case, with a byte array being passed...

  • If the method requires a byte[], that should be used as the argument to the (single) test case.
  • If the method requires a single argument of type byte, then we should generate one test case for each member of the array
  • If the method requires (for example) 3 arguments all of type byte and the array length is 3, then we should generate one test case with the three arguments.

It gets even more complicated when the argument type is object, because an object[] is an object. So, in that case we can't be sure we have done it right.

When in doubt, write a test! 😄

Member

CharliePoole commented Mar 1, 2017

@gcichosz I assigned it to you.

It's a tricky issue. I suggest first ensuring we have sufficient tests to cover all the cases that may arise.

Basically, this problem comes up with all array types. In this case, with a byte array being passed...

  • If the method requires a byte[], that should be used as the argument to the (single) test case.
  • If the method requires a single argument of type byte, then we should generate one test case for each member of the array
  • If the method requires (for example) 3 arguments all of type byte and the array length is 3, then we should generate one test case with the three arguments.

It gets even more complicated when the argument type is object, because an object[] is an object. So, in that case we can't be sure we have done it right.

When in doubt, write a test! 😄

@gcichosz

This comment has been minimized.

Show comment
Hide comment
@gcichosz

gcichosz Mar 28, 2017

Contributor

As I can see, I don't have time for this issue lately, so you can unassign me. I'll come back to it when I have time, and it's still available.

Contributor

gcichosz commented Mar 28, 2017

As I can see, I don't have time for this issue lately, so you can unassign me. I'll come back to it when I have time, and it's still available.

@ChrisMaddock

This comment has been minimized.

Show comment
Hide comment
@ChrisMaddock

ChrisMaddock Mar 28, 2017

Member

No worries - thanks for the update! Hope things calm down for you soon. 😄

Member

ChrisMaddock commented Mar 28, 2017

No worries - thanks for the update! Hope things calm down for you soon. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment