Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

AutoFixture Warning Incorrect
Silvenga
#1 Posted : Tuesday, July 18, 2017 9:27:05 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 1/24/2016(UTC)
Posts: 40
Location: United States of America

Was thanked: 3 time(s) in 3 post(s)
Quote:
AutoFixture is an extension system that allows automatic substitution of test case parameters using randomly generated values. Every time an AutoFixture test case is discovered, its signature is different due to random generation. This causes serious problems for NCrunch and other runners that use selective execution, as test cases become impossible to identify across test runner processes and discovery actions.

Tests that use AutoFixture are not supported by NCrunch. For more information, please refer to http://www.ncrunch.net/d...raints_unique-test-names


We now see the above warning in our code base, alarming many. I'm not sure if the warning is entirely correct as the core library of AutoFixture cannot modify test names. This feature is delegated to other packages, e.g. AutoFixture.Xunit2 or AutoFixture.NUnit3.

See the repo: https://github.com/AutoF...aAttribute.cs&type=

Maybe consider changing the warning to only show when one of the supporting packages is installed. My team uses Autofixture, but only within tests, never within theories (hence we don't have AutoFixture.Xunit2 installed).
Silvenga
#2 Posted : Tuesday, July 18, 2017 9:42:47 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 1/24/2016(UTC)
Posts: 40
Location: United States of America

Was thanked: 3 time(s) in 3 post(s)
A co-worker brought up (whom doesn't want to make a forum account :( ) that the following example was given (I must have missed it):

Code:
namespace XUnitAutoFixture
{
    public class TestFixture
    {
        private static readonly Fixture Fixture = new Fixture();

        public static IEnumerable<object[]> SomeTestData()
        {
            yield return new object[] { Fixture.Create<long>() };
            yield return new object[] { Fixture.Create<long>() };
        }

        [Theory, MemberData(nameof(SomeTestData))]
        public void Test(object value)
        {

        }
    }
}


Yes, AutoFixture messes up NCrunch, but this example does too:

Code:
namespace XUnitAutoFixture
{
    public class TestFixture
    {
        private static readonly Fixture Fixture = new Fixture();

        public static IEnumerable<object[]> SomeTestData()
        {
            yield return new object[] { DateTime.Now.Ticks };
            yield return new object[] { DateTime.Now.Ticks };
        }

        [Theory, MemberData(nameof(SomeTestData))]
        public void Test(object value)
        {

        }
    }
}


But it doesn't require AutoFixture from being installed. Some developers may stop using AutoFixture for the sole reason that NCrunch (which many would consider an expert) said it wasn't supported.
Remco
#3 Posted : Wednesday, July 19, 2017 12:16:41 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Yes, it's true that AutoFixture won't cause problems if it isn't used for providing parameters to test cases or theories. I have a somewhat bias here in that many of the problems I chase are related to inconsistent test case parameters, so I assumed that this was the primary purpose of the library.

I've made a note to revise the warning to avoid alarming people that aren't using the library for parameter substitution. There isn't any feasible way to detect a difference in how the library is used, but I can at least change the wording so that the warning is more specific. If you're not experiencing any of the problems described in the warning link, you can safely ignore the warning.
ewinhong
#4 Posted : Wednesday, July 19, 2017 9:19:56 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

Remco;10798 wrote:
Yes, it's true that AutoFixture won't cause problems if it isn't used for providing parameters to test cases or theories. I have a somewhat bias here in that many of the problems I chase are related to inconsistent test case parameters, so I assumed that this was the primary purpose of the library.

I've made a note to revise the warning to avoid alarming people that aren't using the library for parameter substitution. There isn't any feasible way to detect a difference in how the library is used, but I can at least change the wording so that the warning is more specific. If you're not experiencing any of the problems described in the warning link, you can safely ignore the warning.



This warning is actually not running any of my 2700+ tests. If ncrunch ran the tests, there would be no issue. [img=(- BROKEN LINK -)]autofixture warning but not running any tests[/img]

I previously attempted to use 3.9.0.1 and it did not work at all.

I am going to go back to 3.8.0.3 since it stop running my tests.
Remco
#5 Posted : Wednesday, July 19, 2017 11:34:38 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ewinhong;10802 wrote:

This warning is actually not running any of my 2700+ tests. If ncrunch ran the tests, there would be no issue. [img=(- BROKEN LINK -)]autofixture warning but not running any tests[/img]

I previously attempted to use 3.9.0.1 and it did not work at all.

I am going to go back to 3.8.0.3 since it stop running my tests.


Looking at the img you've linked, it seems that NCrunch is not discovering your tests. This is in no way related to the AutoFixture issues and has nothing to do with the warning being shown.

Something else is going wrong here. Do you have any other warnings being shown? Which version of Xunit are you running? Do your tests work with other runners? (i.e. VSTest, Resharper, etc)
Silvenga
#10 Posted : Thursday, July 20, 2017 12:53:45 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 1/24/2016(UTC)
Posts: 40
Location: United States of America

Was thanked: 3 time(s) in 3 post(s)
Thanks for the response Remoc, I can totally relate to your pain.

We were wondering, depending on how NCrunch's discovery system works, if it would be possible to detect when test signatures change when no IL differences are detected. This would be infinitely more prefered to us developers, IMHO, then a warning when a library is used.
Remco
#11 Posted : Thursday, July 20, 2017 1:11:45 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Silvenga;10804 wrote:

We were wondering, depending on how NCrunch's discovery system works, if it would be possible to detect when test signatures change when no IL differences are detected. This would be infinitely more prefered to us developers, IMHO, then a warning when a library is used.


Unfortunately there isn't a reliable way to do this, because when user code is used to create tests, anything can happen. For example, tests may be generated from an external resource (like a resource file or database), so it's possible for the list of tests to be different without any IL changes detected.

This is, also, completely under the power of the test framework itself. Proper integration with a test framework involves treating it as a service. The framework is interrogated for the list of tests to execute after an assembly is compiled. To try and assume which tests are in an assembly without asking the framework would be to step around this entirely, effectively re-implementing the framework and removing all forwards compatibility with future versions of it. It's a massive problem when you ask a framework for a list of tests that is different every time you ask for them even when no changes are made. If you have tests that change their shape every time they're discovered because of user code, there is nothing in NCrunch or the discovery system that can give you a consistent result.
ewinhong
#6 Posted : Thursday, July 20, 2017 2:26:46 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

Remco;10803 wrote:
ewinhong;10802 wrote:

This warning is actually not running any of my 2700+ tests. If ncrunch ran the tests, there would be no issue. [img=(- BROKEN LINK -)]autofixture warning but not running any tests[/img]

I previously attempted to use 3.9.0.1 and it did not work at all.

I am going to go back to 3.8.0.3 since it stop running my tests.


Looking at the img you've linked, it seems that NCrunch is not discovering your tests. This is in no way related to the AutoFixture issues and has nothing to do with the warning being shown.

Something else is going wrong here. Do you have any other warnings being shown? Which version of Xunit are you running? Do your tests work with other runners? (i.e. VSTest, Resharper, etc)


This screenshot shows that in ncrunch for [img=(- BROKEN LINK -)]VS 2017 3.8.0.3 [/img]

xUnit v 2.2.0

Tests do work with Resharper
(- BROKEN LINK -)Resharper[/url]
Remco
#7 Posted : Friday, July 21, 2017 12:07:05 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ewinhong;10806 wrote:

xUnit v 2.2.0

Tests do work with Resharper
(- BROKEN LINK -)Resharper[/url]


If you look in the Processing Queue Window, do you see any 'Analyse Assembly' tasks in the list?

Also, would you be able to submit an NCrunch bug report after NCrunch has completed building your solution?
ewinhong
#8 Posted : Monday, July 24, 2017 1:54:20 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

Remco;10809 wrote:
ewinhong;10806 wrote:

xUnit v 2.2.0

Tests do work with Resharper
(- BROKEN LINK -)Resharper[/url]


If you look in the Processing Queue Window, do you see any 'Analyse Assembly' tasks in the list?

Also, would you be able to submit an NCrunch bug report after NCrunch has completed building your solution?


(- BROKEN LINK -)


Bug reported

Remco
#12 Posted : Monday, July 24, 2017 11:55:02 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks for sending this through. As you've discovered, the key issue here is an exception being thrown when NCrunch tries to invoke Xunit to discover tests:

System.InvalidCastException: Unable to cast object of type 'Xunit.Sdk.ReflectionAssemblyInfo' to type 'Xunit.Abstractions.IAssemblyInfo'.

These types are convertable under Xunit 2.2. The only reason I can think of why they would fail to convert is if you were using different and incompatible versions of Xunit libraries.

Can you try removing all Nuget and assembly references to Xunit from your test projects, ensure that any Xunit packages under your solution directory are removed, then try reinstalling Xunit via Nuget?
ewinhong
#13 Posted : Tuesday, July 25, 2017 2:57:54 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

Remco;10828 wrote:
Thanks for sending this through. As you've discovered, the key issue here is an exception being thrown when NCrunch tries to invoke Xunit to discover tests:

System.InvalidCastException: Unable to cast object of type 'Xunit.Sdk.ReflectionAssemblyInfo' to type 'Xunit.Abstractions.IAssemblyInfo'.

These types are convertable under Xunit 2.2. The only reason I can think of why they would fail to convert is if you were using different and incompatible versions of Xunit libraries.

Can you try removing all Nuget and assembly references to Xunit from your test projects, ensure that any Xunit packages under your solution directory are removed, then try reinstalling Xunit via Nuget?


I tried removing references and it appears that there is an underlying issue that another external library (specflow) does not work.

I believe xunit.abstraction was the xunit library that was not the current version.

I spent too much time on this. Going back to 3.8.0.3 again
Remco
#14 Posted : Tuesday, July 25, 2017 11:01:23 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ewinhong;10835 wrote:

I tried removing references and it appears that there is an underlying issue that another external library (specflow) does not work.

I believe xunit.abstraction was the xunit library that was not the current version.


It's possible that the version of SpecFlow you're using isn't compatible with Xunit v2.2. This is likely to give you headaches in future, as it means that the behaviour of your test environment will be determined by the sequence in which assemblies are loaded by the JIT. v3.8 may work for you here because it uses a binding redirection to force the test environment to use v2.1 of xunit.abstractions, but this may yield other downstream issues for you. As frustrating as this problem may be, I do recommend resolving it to prevent wasted time in future. Issues like this can result in some truly bizarre errors in tooling.
ewinhong
#15 Posted : Wednesday, July 26, 2017 1:48:26 AM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

Remco;10838 wrote:
ewinhong;10835 wrote:

I tried removing references and it appears that there is an underlying issue that another external library (specflow) does not work.

I believe xunit.abstraction was the xunit library that was not the current version.


It's possible that the version of SpecFlow you're using isn't compatible with Xunit v2.2. This is likely to give you headaches in future, as it means that the behaviour of your test environment will be determined by the sequence in which assemblies are loaded by the JIT. v3.8 may work for you here because it uses a binding redirection to force the test environment to use v2.1 of xunit.abstractions, but this may yield other downstream issues for you. As frustrating as this problem may be, I do recommend resolving it to prevent wasted time in future. Issues like this can result in some truly bizarre errors in tooling.


I attempt using a different machine and visual studio 2017 and it appeared to work but have yet to isolate which is causing the problem. So I’m going to check for differences.
ewinhong
#16 Posted : Wednesday, July 26, 2017 4:56:05 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

ewinhong;10842 wrote:
Remco;10838 wrote:
ewinhong;10835 wrote:

I tried removing references and it appears that there is an underlying issue that another external library (specflow) does not work.

I believe xunit.abstraction was the xunit library that was not the current version.


It's possible that the version of SpecFlow you're using isn't compatible with Xunit v2.2. This is likely to give you headaches in future, as it means that the behaviour of your test environment will be determined by the sequence in which assemblies are loaded by the JIT. v3.8 may work for you here because it uses a binding redirection to force the test environment to use v2.1 of xunit.abstractions, but this may yield other downstream issues for you. As frustrating as this problem may be, I do recommend resolving it to prevent wasted time in future. Issues like this can result in some truly bizarre errors in tooling.


I attempt using a different machine and visual studio 2017 and it appeared to work but have yet to isolate which is causing the problem. So I’m going to check for differences.



Just so you are aware of what I found in my investigation:

I loaded an issue with Autofixture. https://github.com/AutoF.../AutoFixture/issues/786

This is the probable cause to my issue.
Remco
#17 Posted : Wednesday, July 26, 2017 10:40:03 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ewinhong;10852 wrote:

Just so you are aware of what I found in my investigation:

I loaded an issue with Autofixture. https://github.com/AutoF.../AutoFixture/issues/786

This is the probable cause to my issue.


Ouch, that's nasty. It's good that they've confirmed a fix is coming. Thanks for confirming the was the source of the issue.
ewinhong
#18 Posted : Tuesday, August 1, 2017 1:13:44 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 14
Location: United States of America

After performing numerous install and reinstall, I realized yesterday that I was on v 3.8.0.3 when I thought I was on 3.10.0.20. So I went through the same process I did last time.

But when I thought I did the same process, ncrunch would not discover the tests.

So this caused me to try changing settings on my work machine since I knew ncrunch discovered tests on my home machine.

So the first setting I changed was Pre-load all assembly into test environment from true to false.

This detected the tests as expected.

So I have to ask this previously worked to detect tests with this setting being true on v3.8.0.3.
Remco
#19 Posted : Tuesday, August 1, 2017 11:47:48 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
ewinhong;10905 wrote:

So I have to ask this previously worked to detect tests with this setting being true on v3.8.0.3.


Sorry - I'm not completely sure if I understand this question. Are you still receiving the same exception around type conversion? Or is this a new problem?

Preloading assembly references does have the potential to solve this problem under specific circumstances. This setting forces the task runner to load its assembly references prior to invoking the test framework, so there is less possibility for variation during the loading of these references. If you have a version clash on an xunit assembly in your solution, this setting won't solve the clash, but it may change the sequence so that the clash is not noticeable.
sgrassie
#9 Posted : Thursday, August 10, 2017 10:26:58 AM(UTC)
Rank: Member

Groups: Registered
Joined: 6/25/2015(UTC)
Posts: 14
Location: United Kingdom

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
Remco;10798 wrote:
Yes, it's true that AutoFixture won't cause problems if it isn't used for providing parameters to test cases or theories. I have a somewhat bias here in that many of the problems I chase are related to inconsistent test case parameters, so I assumed that this was the primary purpose of the library.

I've made a note to revise the warning to avoid alarming people that aren't using the library for parameter substitution. There isn't any feasible way to detect a difference in how the library is used, but I can at least change the wording so that the warning is more specific. If you're not experiencing any of the problems described in the warning link, you can safely ignore the warning.

I came here to post about this self same thing and found this thread. My current team doesn't use xunit autodata theories either, so the warnings are essentially false for us.

Good to know we can at least ignore them until the warning in NCrunch is refined.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.130 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download