Search Unity

[UnitTest][NSubstitute]After upgrade to Unity2017, nor Unity neitherVS2017 can execute UnitTests

Discussion in 'Editor & General Support' started by FlorentFal, Oct 16, 2017.

  1. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    41
    Hello,

    I work on a project created on Unity5.6. I created dozen of UnitTests that I executed into VisualStudio. Theses tests do a heavy use of NSubstitute .

    I've done an upgrade to Unity2017 that now embeded a custom version of NUnit. These custom version of NUnit, I assume, add some new attributes as "UnityTest"...


    But it seems that version is no more compliant with unitTest execution out of Unity editor. VisualStudio give me following errors :


    In same time, trying to execute same UnitTest in UnityEditor via new "Test Runner" windows "editor mode" give following error, which I assume mean that Unity embeded version of NUnit is missing something...? :


    Unity's UnitTest team support is welcome ! :)

    Thank you

    Florent
     
    Last edited: Oct 16, 2017
  2. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    41
    Found this issue but don't known what mean its status "Fix in review"..will try last stable Unity version...
     
  3. networm

    networm

    Joined:
    Sep 15, 2015
    Posts:
    6
  4. XenoRo

    XenoRo

    Joined:
    Jul 22, 2014
    Posts:
    22
    I have the exact same problem
     
  5. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    41
    Hi here's status for both problem :

    System.Reflection.TargetInvocationException at Resharper UnitTest execution : will not be fixed - (explain at https://issuetracker.unity3d.com/is...ion-when-running-nunit-tests-in-visual-studio)

    System.MissingMethodException : Method not found: 'System.Reflection.Emit.TypeBuilder.DefineProperty' : , aka NSubstitute problem : I've open a issue at https://fogbugz.unity3d.com/default.asp?959847_19ldibmfh11rp2s2, which is still "open" but which cannot be found on public issue tracker, I don't know what that mean about this problem resolution...


    Answer by networm did not help but I can't remeber why (I will give it a new try this week), did you try Unity 2017 beta version ?? => KO on Unity 2017.3.0b10

    If you found any workaround, please let a comment here !

     
    Last edited: Nov 28, 2017
  6. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    41
    I've juste found this recent answer about NSubstitute integration with Unity 2017, will also check it this week.
     
  7. XenoRo

    XenoRo

    Joined:
    Jul 22, 2014
    Posts:
    22
    Ok... A few steps in the right direction, and a "workaround" of sorts:
    1) I could confirm that the problem is caused by Unity's own custom-built NUnit being incompatible with ReSharper's test-runner.
    2) I could confirm that the unit-tests worked before due to Unity's custom NUnit being based on an older version of NUnit before Unity2017; don't ask me how that made it work, however; because I can't make any sense out of how an older, more divergent version worked, and a "closer" version doesn't. It's probably dark magic. (like much in Unity, unfortunately)
    3) The "workaround" (not really, but at least we can unit-test) is to use Unity's test-runner, in the editor. External test-runners are unlikely to work out-of-the-box.
    4) Maybe, just maybe, ReSharper can still be made to target Unity's custom NUnit... ReSharper has such "custom NUnit" option under ReSharper -> Options -> Tools -> Unit Testing -> NUnit -> Custom NUnit installation... Checking the "Use specified custom NUnit" checkbox and specifying the path to Unity's custom NUnit (That's C:\Program Files\Unity\MonoDevelop\Addins\NUnit on windows) gets rid of the exception (YAY!), but still results in "Inconclusive: Test not run" (DOH!) for some other reason I haven't identified yet.
     
  8. networm

    networm

    Joined:
    Sep 15, 2015
    Posts:
    6
  9. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    41
    @networm , your asset solved the resharper integration probleme! Thank you very much !:)
     
  10. nikomikulicic

    nikomikulicic

    Joined:
    Dec 3, 2012
    Posts:
    4
    @FlorentFal I've found this NSubstitute post where they discuss the same problem I believe is bothering you (and me). They've concluded it's a Unity issue. As a workaround for now, I'll be writing functions instead of properties even though it's not always a pleasant thing to do.

    Do you have any updates on System.MissingMethodException issue you've posted? Anyone else still encountering this issue?
     
  11. Zwer99

    Zwer99

    Joined:
    Oct 24, 2013
    Posts:
    24
    @sejton I have the same problem when using NSubstitute
     
  12. nikomikulicic

    nikomikulicic

    Joined:
    Dec 3, 2012
    Posts:
    4
    Again, refering to this NSubstitute post, I kind man/woman named benji7425 recently added a comment saying:

    Thank you kind sir. I've successfully resolved this issue using NSubstitute version 2.0.1-rc. @Zwer99, and others, I'm referencing that post here as I hope you and others will find it useful as I did.
     
unityunity