0

my project solution is based on Sitecore Helix Visual Studio Templates by Ander's Laub. Im trying to write Unit tests using XUnit, but none of the tests are running and not even failing.

For test projects, I have tried using Project based on Class Library(.NET Framework), Projects based on Sitecore Helix Visual Studio Templates by Ander's Laub.

Packages used:

  1. XUnit(2.4.1)
  2. XUnit.Runner.VisualStudio(2.4.3)
  3. XUnit.Runner.Console(2.4.1)

Framework: .NET 4.8

Visual Studio 2019: v16.8.5

The output im getting:

enter image description here

DemoTests.cs

public class DemoTests
    {

        [Fact]
        public void DemoTestForPassingOnly()
        {
            double expected = 5;
            double actual = 4;
            Assert.Equal(expected, actual);
        }

     }

Test Run Output window:

ProjectData: Could not find project with GUID 09fe023c-998c-4a4c-a896-bc27884e7aaf
ProjectData: Could not find project with GUID 09fe023c-998c-4a4c-a896-bc27884e7aaf
---------- Starting test run ----------
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.3+1b45f5407b (64-bit Desktop .NET 4.0.30319.42000)
No test matches the given testcase filter `FullyQualifiedName=Linde.Foundation.SitecoreExtensions.Tests.DemoTests.DemoTestForPassingOnly` in C:\SourceTree\lindemh-sitecore\bin\Debug\Linde.Foundation.SitecoreExtensions.Tests.dll
========== Test run finished: 0 Tests run in 1.3 sec (0 Passed, 0 Failed, 0 Skipped) ==========


I have tried building a separate Console Application with Tests project to make sure whether this is a Visual Studio Issue, but it is running/failing/passing inside the console application, but not inside the Sitecore Project.

Do I have to configure the solution differently in order for the Tests to run successfully?

15
  • I'm guessing you tried clicking the play button in the test explorer there?
    – Richard Seal
    Apr 12 at 13:07
  • Can you verify what versions have you used for the XUnit.runer nuget packages? Apr 12 at 13:24
  • @Cristi : added in the question description.
    – Suman Baul
    Apr 13 at 2:14
  • @Richard Yes tried both of the buttons.
    – Suman Baul
    Apr 13 at 2:15
  • Would you mind adding screenshot of output window after you have done rebuild solution, also check that window after you have pressed Run Test button as this window does not provide enough information. Apr 13 at 7:08
0

For simple unit tests using xunit I only have those references in my package :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="xunit" version="2.4.1" targetFramework="net462" />
  <package id="xunit.abstractions" version="2.0.3" targetFramework="net462" />
  <package id="xunit.analyzers" version="0.10.0" targetFramework="net462" />
  <package id="xunit.assert" version="2.4.1" targetFramework="net462" />
  <package id="xunit.core" version="2.4.1" targetFramework="net462" />
  <package id="xunit.extensibility.core" version="2.4.1" targetFramework="net462" />
  <package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net462" />
  <package id="xunit.runner.console" version="2.4.1" targetFramework="net462" developmentDependency="true" />
  <package id="xunit.runner.visualstudio" version="2.4.1" targetFramework="net462" developmentDependency="true" />
</packages>

So I believe the XUnit.Runner.VisualStudio(2.4.3) should be 2.4.1.

Then a simple test could look like that

using aProject.Foundation.Utilities.Extensions;
using Xunit;

namespace aProject.Foundation.Utilities.Tests
{
    public class ExtensionsTests
    {
        public class StringExtensionTests
        {
            [Theory]
            [InlineData("some awesome string")]
            [InlineData("  some  awesome  string  ")]
            public void Should_returnValidSlug_When_passingStringWithSpaces(string name)
            {
                Assert.Equal("some-awesome-string", name.ToSlug());
            }
        }
    }
}
2
  • Hi Jean, so i have checked it all the packages are installed correctly. Is this anyway related to the solution template by Anders Laub im using?
    – Suman Baul
    Apr 14 at 6:01
  • I can't tell, but I would rather check other boxes before looking that way. Can you double check this q/a : stackoverflow.com/questions/35103781/… Apr 14 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.