SkippableTheory and empty source input from MemberData will produce exception
Closed this issue · 2 comments
kenjiuno commented
ParserTest.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Xunit;
namespace SkippableTheoryAndMemberDataAndEmpty
{
public class ParserTest
{
[SkippableTheory]
[MemberData(nameof(ProvideFiles))]
public void TestFile(string file)
{
File.ReadAllText(file); // test this in own code...
}
public static IEnumerable<object[]> ProvideFiles()
{
foreach (var file in Directory.GetFiles(".", "*.file-extension"))
{
yield return new object[] { file };
}
}
}
}
dotnet test
Determining projects to restore...
All projects are up-to-date for restore.
SkippableTheoryAndMemberDataAndEmpty -> H:\Proj\SkippableTheoryAndMemberDataAndEmpty\SkippableTheoryAndMemberDataAndEmpty\bin\Debug\net6.0\SkippableTheoryAndMemberDataAndEmpty.dll
Test run for H:\Proj\SkippableTheoryAndMemberDataAndEmpty\SkippableTheoryAndMemberDataAndEmpty\bin\Debug\net6.0\SkippableTheoryAndMemberDataAndEmpty.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.3.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.47] SkippableTheoryAndMemberDataAndEmpty.ParserTest.TestFile [FAIL]
Failed SkippableTheoryAndMemberDataAndEmpty.ParserTest.TestFile [< 1 ms]
Error Message:
System.InvalidOperationException : The test method expected 1 parameter value, but 0 parameter values were provided.
Failed! - Failed: 1, Passed: 0, Skipped: 0, Total: 1, Duration: < 1 ms - SkippableTheoryAndMemberDataAndEmpty.dll (net6.0)
The exception message
System.InvalidOperationException : The test method expected 1 parameter value, but 0 parameter values were provided.
I wonder why...
repo https://github.com/kenjiuno/SkippableTheoryAndMemberDataAndEmpty
AArnott commented
So is the idea that GetFiles
produced an empty list? If so, why do you expect something other than an error? Theories are generally expected to run with at least 1 test case, and usually more.
kenjiuno commented
Thanks for reply.
And sorry it was my misunderstand that SkippableTheory can work with empty list.
This is enough that this not problem of Xunit.SkippableFact. Sorry for taking your time.
I'll check more about Xunit itself.