Skip to content
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

Snapshot Test fails on Azure #149

Open
tsinghammer opened this issue May 11, 2022 · 4 comments
Open

Snapshot Test fails on Azure #149

tsinghammer opened this issue May 11, 2022 · 4 comments

Comments

@tsinghammer
Copy link

tsinghammer commented May 11, 2022

Describe the bug
I have two Snapshooter tests which's output are dictionaries. Locally everything works fine, the snapshot files are being generated the first time and then match from then on.
However the same tests run on Azure fail with the following exception:

Stack trace

[xUnit.net 00:00:03.95]     Mapping.Tests.Test.MapperTest.Test_Bug_460395_oa136372 [FAIL]
  Failed Mapping.Tests.Test.MapperTest.Test_Bug_460395_oa136372 [989 ms]
  Error Message:
   Snapshooter.Exceptions.SnapshotTestException : The snapshot full name could not be evaluated. This error can occur, if you use the snapshot match within a async test helper child method. To solve this issue, use the Snapshot.FullName directly in the unit test to get the snapshot name, then reach this name to your Snapshot.Match method.
  Stack Trace:
     at Snapshooter.Xunit.XunitSnapshotFullNameReader.ReadSnapshotFullName()
   at Snapshooter.SnapshotFullNameResolver.ResolveSnapshotFullName(String snapshotName, String snapshotNameExtension)
   at Snapshooter.Snapshooter.ResolveSnapshotFullName(String snapshotName, SnapshotNameExtension snapshotNameExtension)
   at Snapshooter.Xunit.Snapshot.FullName()
   at Snapshooter.Xunit.Snapshot.Match(Object currentResult, Func`2 matchOptions)

The tests are not async.
Do you have any idea what could cause this?
Btw. there are already other Snapshooter tests in this project running successfully both locally and on Azure.

@nscheibe
Copy link
Member

Hi Tassilo, this could happen if the test is executed in release mode... can you check this shortly?

@tsinghammer
Copy link
Author

tsinghammer commented May 12, 2022

It seems that a foreach loop in the test code is causing the issue.
This code succeeds on Azure:

    record Test(string Name);

    [Fact]
    public void Test_Bug_460395_oa136372()
    {
        List<Test> testItems = new();
        // foreach (string item in new string[] { "test1", "test2", "test3" })
        // {
        //     testItems.Add(new Test(item));
        // }
        testItems = new string[] { "test1", "test2", "test3" }.Select(x => new Test(x)).ToList();
        Snapshot.Match(testItems);
    }
However this one fails:
    record Test(string Name);

    [Fact]
    public void Test_Bug_460395_oa136372()
    {
        List<Test> testItems = new();
        foreach (string item in new string[] { "test1", "test2", "test3" })
        {
            testItems.Add(new Test(item));
        }
        // testItems = new string[] { "test1", "test2", "test3" }.Select(x => new Test(x)).ToList();
        Snapshot.Match(testItems);
    }

@tsinghammer
Copy link
Author

tsinghammer commented May 13, 2022

Stack trace:

 Failed Mapping.Tests.Test.MapperTest.Test_Bug_460395_oa136372 [183 ms]
  Error Message:
   Snapshooter.Exceptions.SnapshotTestException : The snapshot full name could not be evaluated. This error can occur, if you use the snapshot match within a async test helper child method. To solve this issue, use the Snapshot.FullName directly in the unit test to get the snapshot name, then reach this name to your Snapshot.Match method.
  Stack Trace:
     at Snapshooter.Xunit.XunitSnapshotFullNameReader.ReadSnapshotFullName()
   at Snapshooter.SnapshotFullNameResolver.ResolveSnapshotFullName(String snapshotName, String snapshotNameExtension)
   at Snapshooter.Snapshooter.ResolveSnapshotFullName(String snapshotName, SnapshotNameExtension snapshotNameExtension)
   at Snapshooter.Xunit.Snapshot.FullName()
   at Snapshooter.Xunit.Snapshot.Match(Object currentResult, Func`2 matchOptions)

@tsinghammer
Copy link
Author

I have an additional problem with different behavior local vs Azure:
There is a difference in the decimal places being rendered:

↓ (pos 6773) Expected: ···\"DecRangeMin\": 0.0,\n \"DecRangeMax\": 99.000000,\n ··· Actual: ···\"DecRangeMin\": 0.000000,\n \"DecRangeMax\": 99.00000···

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants