Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xunit test framework fails to find tests #20

Open
Blueknight10001 opened this issue Jun 20, 2019 · 6 comments
Open

Xunit test framework fails to find tests #20

Blueknight10001 opened this issue Jun 20, 2019 · 6 comments

Comments

@Blueknight10001
Copy link

Blueknight10001 commented Jun 20, 2019

When writing test classes and using the line [assembly: Xunit.TestFramework("Elastic.Xunit.Sdk.ElasticTestFramework", "Elastic.Xunit")], none of the tests (even the non Elastic tests) are discovered. I'm sure it's something simple I'm missing, but I can't find anything. I've used Visual Studio 2019 and the command line to no avail.

It's almost an exact copy of the ExampleMinimal.

using API.Entities;
using Elastic.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using Nest;
using System;
using System.Collections.Generic;
using System.Text;
using FluentAssertions;
using Elastic.Xunit;
using Elastic.Xunit.Sdk;

namespace TrackItTest
{
    public class MyTestCluster : XunitClusterBase
    {
        public MyTestCluster() : base(new XunitClusterConfiguration("6.2.0") { })
        {
        }

    }

    public class ExampleTest : IClusterFixture<MyTestCluster>
    {
        private ElasticClient _client;
        public ExampleTest(MyTestCluster cluster)
        {
            _client = cluster.GetOrAddClient(c =>
            {
                var nodes = cluster.NodesUris();
                var connectionPool = new StaticConnectionPool(nodes);
                var settings = new ConnectionSettings(connectionPool)
                    .EnableDebugMode();
                return new ElasticClient(settings);
            });
        }

        [I]
        public void GetTrackableTest()
        {
            var rootNodeInfo = _client.RootNodeInfo();

            rootNodeInfo.Name.Should().NotBeNullOrEmpty();
        }
    }
}
`
@Mpdreamz
Copy link
Member

HI @Blueknight10001

This ticket is a bit stale (all my fault), did you get this working? Otherwise seeing your project file would help to further diagnose.

@jpdunn
Copy link

jpdunn commented Jul 14, 2020

I've also been able to reproduce this issue using the example in the readme.

My test cluster is created like so:

using Elastic.Elasticsearch.Xunit;

[assembly: Xunit.TestFrameworkAttribute("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]

namespace Elastic.Test {
    public class TestCluster : XunitClusterBase {
        public TestCluster() : base(new XunitClusterConfiguration("7.8.0")) { }
    }
}

And used in the test:

using Elastic.Elasticsearch.Xunit;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;

namespace Elastic.Test {
    public class ExampleTest {

        public ExampleTest(TestCluster cluster) {
            this.Client = cluster.GetOrAddClient(c => {
                var nodes = cluster.NodesUris();
                var connectionPool = new StaticConnectionPool(nodes);
                var settings = new ConnectionSettings(connectionPool).EnableDebugMode();
                return new ElasticClient(settings);
            });
        }

        private ElasticClient Client { get; }

        [I]
        public void SomeTest() {
            var rootNodeInfo = this.Client.RootNodeInfo();

            rootNodeInfo.Name.Should().NotBeNullOrEmpty();
        }
    }
}

My project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Elastic.Elasticsearch.Xunit" Version="0.2.4" />
    <PackageReference Include="NEST" Version="7.8.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />

    <PackageReference Include="FluentAssertions" Version="5.1.2" />
  </ItemGroup>

</Project>

I've also tried updating the versions of NEST and Xunit but that doesn't seem to change anything. I'm running the tests through the Test Explorer in Visual Studio Professional 2019 (16.6.2)

@schrufygroovy
Copy link

schrufygroovy commented Sep 14, 2020

any news on this? I am experiencing exactly the same issue. @jpdunn , @Blueknight10001 have you been able to somehow resolve the problem?

for me I was able to resolve it by downgrading xunit references to:

<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />

@MEmanuelsson
Copy link

Also curious about the progress of this issue? Using xunit 2.4.x doesn't seem to find any tests but using 2.3.1 as stated above works fine?

@watfordsuzy
Copy link

I can confirm this is a problem with xUnit 2.4.X (Visual Studio 2019) that seems to work fine with 2.3.1.

@paulomac1000
Copy link

Hi, I found solution :)

  1. Completely remove this entry from the project:
[assembly: Xunit.TestFrameworkAttribute("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]
  1. Remove the constructor injection of your cluster object:
public ExampleTest(TestCluster cluster)

Should be:

public ExampleTest()
  1. Create your cluster obiect in constructor using new
var cluster = new TestCluster();
  1. Mark the tests with the Fact attribute instead of I.
[I]
public void SomeTest() {

Should be:

[Fact]
public void SomeTest() {

All my tests are green. The versions of the packages that I use today are the newest.

net6.0
"Elastic.Elasticsearch.Xunit" Version="0.3.1"
"Microsoft.NET.Test.Sdk" Version="17.2.0"
"xunit" Version="2.4.1"
"xunit.runner.visualstudio" Version="2.4.5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants