testfx icon indicating copy to clipboard operation
testfx copied to clipboard

StackOverflowException running tests with DynamicData where the target class uses JToken (and dynamic).

Open smohrman-godaddy opened this issue 2 years ago • 5 comments

Description

A StackOverflowException occurs running a DataTestMethod test using DynamicData when the target POCO class includes a JToken as a Dictionary TValue type. Note, the same thing occurs if I change JToken to dynamic.

Steps to reproduce

See attached sample solution and run tests.

Expected behavior

The test receives the test case deserialized as expected without a StackOverflowException occurring.

Actual behavior

The Newtonsoft.JSON deserialization works as expected -- the object's dictionary contains one item whose value is JArray -- however, there is XML serialization happening in the DynamicDataAttribute's code that is causing a StackOverflowException.

Environment

  • macOS Big Sur
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>

        <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
        <PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
        <PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
        <PackageReference Include="coverlet.collector" Version="3.1.2">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="NFluent" Version="2.8.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\MSTestSerializationIssue\MSTestSerializationIssue.csproj" />
    </ItemGroup>

    <ItemGroup>
      <None Remove="Resources\Example.json" />
      <EmbeddedResource Include="Resources\Example.json" />
    </ItemGroup>

</Project>

MSTestSerialization.zip

smohrman-godaddy avatar Mar 10 '22 23:03 smohrman-godaddy

FWIW, I am also seeing this.

krijohan avatar Mar 22 '22 12:03 krijohan

I am also having this issue. I already spent many hours investigating this issue, without any solution. Any Test Method that use DynamicData with more complex data type like objects and JObjects are failing. But, if I use simple parameters like strings or numbers it works.

ricardopaulob avatar Jun 16 '22 13:06 ricardopaulob

Encountered this as well. For now i'll probably make a workaround by passing indices of array of test data objects to the test method but i'd like to see a proper solution...

pushist1y avatar Jun 23 '22 11:06 pushist1y

Having same issue. Version 2.2.3 of MSTest.TestAdapter works as expected so for now had to downgrade as a workaround.

andriusfl avatar Jun 27 '22 15:06 andriusfl

Please see this for solution.

andriusfl avatar Sep 16 '22 18:09 andriusfl

I am currently investigating this issue and it's not linked to the test ID generation (my initial thought). It seems to be linked to some interaction between Test Platform and MSTest because MSTest 2.2.3 does work as long as I stay on 16.X of TP but using MSTest 2.2.4+ with TP 16.X also fails.

I will dig deeper to understand what's going-on.

Evangelink avatar Oct 13 '22 10:10 Evangelink

Hey folks! It looks like it was fixed by some changes we did in MSTest in the new release we are working on. I have added a test case (and did some manual test) and I cannot repro on main of MSTest (I can repro using released version up to 2.2.10).

Evangelink avatar Oct 27 '22 19:10 Evangelink