mehdi bennie
mehdi bennie

Reputation: 21

Got an issue unit testing with NUnit and an asp.net class that inherits

First sorry for my English, it's not my native language.

I work on an Asp.Net application with a homemade framework by my company.

I have an issue when I start unit tests with NUnit framework. I want to test methods that are in a class who inherits from an other but I have many errors before started any tests :

NUnit Adapter 3.12.0.0: Test execution started Running all tests in C:\PRIV\Projects\WebSite0\test\bin\Debug\test.dll NUnit3TestExecutor converted 1 of 1 NUnit test cases SetUp failed for test fixture test.Class1 System.InvalidOperationException : Aucune implémentation fournie pour ExecEnv à CDM.DevbCommon.Global.ExecEnv.get_Implementation() dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbcommon\Global\ExecEnv.cs:ligne 38 à CDM.DevbCommon.TraceLog.TraceBase.GetObjectFromStorage() dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbcommon\TraceLog\TraceBase.cs:ligne 37 à CDM.DevbCommon.Toolkit.DocReflectionToolkit.GetDocumentation(Assembly asm) dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbcommon\Toolkit\DocReflectionToolkit.cs:ligne 115 à CDM.DevbCommon.Toolkit.DocReflectionToolkit.GetDocumentation(Type type) dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbcommon\Toolkit\DocReflectionToolkit.cs:ligne 46 à CDM.DevbCommon.Navigation.ReflexiveSteps.Reflection.ReflexiveActionProviderBase.SetupSignature(PublicStepSignature Signature) dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbwebapplication4\Navigation\ReflexiveSteps\Reflection\ReflexiveActionProviderBase.cs:ligne 371 à CDM.DevbCommon.Navigation.ReflexiveSteps.PageStep..ctor() dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbwebapplication4\Navigation\ReflexiveSteps\Steps\PageStep.cs:ligne 27 à CDM.DevbCommon.Navigation.ReflexiveSteps.ObjectPageStep`1..ctor() dans d:\BuildAreas\mk_build\DEVBCOMMON\V5.210\PROJECTS\devbwebapplication4\Navigation\ReflexiveSteps\Steps\ObjectPageStep.cs:ligne 27 à CDM.WebSite0.Commands.EmptyPage..ctor() à test.Class1..ctor() dans C:\PRIV\Projects\WebSite0\test\Class1.cs:ligne 17 NUnit Adapter 3.12.0.0: Test execution complete

When I hide the inheritance, the unit test works normally without problems. But with the inheritance, I receive a System.InvalidOperationException

Here the unit test class :

namespace test
{
    [TestFixture]
    public class Class1 
    {
        private readonly EmptyPage vm = new EmptyPage();

        [Test]
        public void TestAddition()
        {
            double actAddNumberResult = vm.AddNumber(5, 7);
            Assert.That(actAddNumberResult, Is.EqualTo(12) );
        }


And here the class to test :

 public class EmptyPage : ObjectPageStep<EmptyPageViewModel>
    {

        public void Prepare()
        {
        }

        public double AddNumber(double nombre1, double nombre2)
        {
            return nombre1 + nombre2;
        }

I tried with XUnit and I have the same problem.

Any idea?

Upvotes: 1

Views: 310

Answers (1)

mehdi bennie
mehdi bennie

Reputation: 21

I have found what is the problem. From the start, i forgot to tell you but the class to test was Internal access. I changed to public to make it visible. i changed it again to Internal and add in Properties/AssemblyInfo.cs

[assembly: InternalsVisibleTo("TestClass")]

Now it works, thank you guys for your Help

Upvotes: 1

Related Questions