slickchick2
slickchick2

Reputation: 137

Trying to create an NUnit test for WPF User Control

I have referenced my WPF project to an NUnit Test Project I made. I am trying to call a function of it but I get the following compilation error:

Reference to type 'DependencyObject' claims it is defined in 'WindowsBase', but it could not be found

I have added PresentationFramework, PresentationCore and WindowsBase as references in the "Assemblies" section of the NUnit test but no go... Not sure what I'm doing wrong... the code is very basic...

using NUnit.Framework;
using System.Collections.Generic;
using System.Threading;
using CM;

namespace Tests
{
    [TestFixture, Apartment(ApartmentState.STA)]
    public class Tests
    {
        InstUserControl userControlMV = new InstUserControl ();

        [Test]
        public void Test1()
        {
            List<string> pOptions = new List<string>() { "2x4", "4x6" };
            userControlMV.SetPOptions(pOptions);
            Assert.Pass();
        }
    }
}

Anyone know what I'm doing wrong.

Upvotes: 0

Views: 2708

Answers (1)

mm8
mm8

Reputation: 169190

You cannot create a NUnit Test Project (.NET Core) to test a WPF application that targets the .NET Framework. Here is what you should do:

  • Create a new Unit Test Project (.NET Framwork)
  • Install the NUnit and NUnit3TestAdapter NuGet packages into it
  • Add a reference to the WPF project to be tested
  • Add a reference to PresentationFramework.dll
  • Add a reference to PresentationCore.cll
  • Add a reference to WindowsBase.dll
  • Run your tests.

Upvotes: 2

Related Questions