elastic / elasticsearch-net-abstractions

Auxiliary tooling for elastic/elasticsearch-net that does not benefit from the rigorous version branching of that repository
Apache License 2.0
25 stars 14 forks source link

Xunit test framework fails to find tests #20

Open Blueknight10001 opened 5 years ago

Blueknight10001 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

Hi, I found solution :)

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

    Should be:

    public ExampleTest()
  3. Create your cluster obiect in constructor using new
    var cluster = new TestCluster();
  4. 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"