Проблемы с автоматическим обнаружением тестов с помощью TestPlatform в .NET.C#

Место общения программистов C#
Ответить
Гость
 Проблемы с автоматическим обнаружением тестов с помощью TestPlatform в .NET.

Сообщение Гость »


I am developing a unit testing framework with c#. I am using the official Microsoft.TestPlatform library and I have already implemented

Код: Выделить всё

ITestDiscoverer
and

Код: Выделить всё

ITestExecutor
.
What I am using to determine that a method is a test is the

Код: Выделить всё

MyTestAttribute
attribute.
MyTestAttribute:

Код: Выделить всё

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class MyTestAttribute : Attribute
{
}
TestDiscoverer:

Код: Выделить всё

[DefaultExecutorUri(Constants.ExecutorUriString)]
[FileExtension(".dll")]
internal class TestDiscoverer : ITestDiscoverer
{
public void DiscoverTests(IEnumerable sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
{
//Discover tests code
//If the method use MyTestAttribute is a test
}
}
TestExecutor:

Код: Выделить всё

[ExtensionUri(Constants.ExecutorUriString)]
internal class TestExecutor : ITestExecutor
{
public void Cancel()
{
//Cancel code
}

public void RunTests(IEnumerable? testCases, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
//Run tests code
}

public void RunTests(IEnumerable? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle)
{
//Run tests code
}
}
So far everything works well, if I have a method that uses the

Код: Выделить всё

[MyTest]
attribute when I run the tests it is detected.

Код: Выделить всё

[MyTest]
public void Should_Be_A_Test()
{
//Unit test code
}
Изображение
The problem is that the test is only visible in the test explorer once I run it, and not when the test is created. To better visualize the problem I am going to show a comparison with the xUnit framework, which is the behavior I want to achieve.
Creation of tests:
  • MyFramework

Код: Выделить всё

[MyTest]
public void Should_Be_A_Test()
{
//Unit test code
}
  • xUnit

Код: Выделить всё

[Fact]
public void Should_Be_True()
{
Assert.True(true);
}
Test explorer results:
Before running the tests
Изображение
As you can see in the image, just by creating the test in xUnit it is already detected, but the methods that use are not detected.
After running the tests
Изображение
Once I run the tests, it is detected and works correctly.
My question is, how can I reproduce that behavior that xUnit has?.
I tried to find how to do it in xUnit by looking at the source code but I couldn't find how to do it.


Источник: https://stackoverflow.com/questions/781 ... orm-in-net
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»