1

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:

Since Im not able to post images, here is the Text Explorer details: Group Summary

Linde.Foundation.SitecoreExtensions.Tests
  Tests in group: 1

Outcomes
   1 Not Run

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?

1 Answer 1

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());
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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