Unit Tests with Shouldly statement fail

807 Views Asked by At

Since some days all my C# unit tests in Visual Studio running on my local machine are raising following TypeInitializationException when reaching the first Shouldly statement:

The type initializer for 'Shouldly.ShouldlyConfiguration' threw an exception

with the inner exception

Illegal characters in path

And a stack trace:

at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Shouldly.Configuration.DiffTool.<>c__DisplayClass10_0.<GetFullPath>b__2(String path)
at System.Linq.Enumerable.<>c__DisplayClass7_0`3.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Shouldly.Configuration.DiffTool.GetFullPath(String fileName)
at Shouldly.Configuration.DiffTool.Discover(String path)
at Shouldly.Configuration.DiffTool..ctor(String name, String path, ArgumentGenerator argGenerator)
at Shouldly.Configuration.KnownDiffTools..ctor()
at Shouldly.Configuration.KnownDiffTools..cctor()

There is a similar issue on https://github.com/shouldly/shouldly/issues/422 but my PATH Environment is correct.

I get the same error for any Unit Test Project Independent of the path.

Even for the simplest test as

  [TestClass]
  public class UnitTest2
  {
    [TestMethod]
    public void TestMethod1()
    {
      int i = 1;
      i.ShouldBe(1);
    }
  }

On other machines I cannot reproduce the issue for the same tests.

1

There are 1 best solutions below

1
NP3 On BEST ANSWER

Based on that stack trace, the path to your diff tool is not a valid path.

Shouldly retrieves all paths from the PATH variable and tries to "guess" the path to one of the pre-defined diff tools.

When one of the paths is invalid, this exception is raised. A solution is currently implmented. See https://github.com/shouldly/shouldly/pull/423