I am developing a unit testing framework with c#. I am using the official Microsoft.TestPlatform library and I have already implemented
Код: Выделить всё
ITestDiscovererКод: Выделить всё
ITestExecutorWhat I am using to determine that a method is a test is the
Код: Выделить всё
MyTestAttributeMyTestAttribute:
Код: Выделить всё
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class MyTestAttribute : Attribute
{
}
Код: Выделить всё
[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
}
}
Код: Выделить всё
[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
}
}
Код: Выделить всё
[MyTest]Код: Выделить всё
[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);
}
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
Код: Выделить всё
MyTestAfter 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
Мобильная версия