asherber / Xunit.Priority

Provides an ITestCaseOrderer that allows you to control the order of execution of Xunit tests within a class.
Apache License 2.0
49 stars 2 forks source link

DefaultPriority bug #7

Closed sarowa36 closed 12 months ago

sarowa36 commented 12 months ago

Hello i have problem about your library. when i use defaultpriority attribute some method who have bigger priority than defaultpriority value its doesnt work/trigger.

 [TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)
     ,DefaultPriority(0)]
 public class ContentControllerTests
 {
     HttpClient client { get; set; }
     static int DefaultFirstItemId { get { return 1; } }
     public ContentControllerTests()
     {
         var server = new TestServer(new WebHostBuilder().UseStartup<VideoSite.Program>());
         client = server.CreateClient();
         Environment.SetEnvironmentVariable("IsInUnitTest", "1");
     }
     [Fact, Priority(-10)]
     public async void Create()
     {
         var data = new ContentViewModel();
         ByteArrayContent img = CreateImageContentForTest.Create();
         var postData = ObjectToMultipartFormDataConverter.Convert(data);
         postData.Add(img, "File", "test.png");

         var res = await client.PostAsync("api/content/create", postData);
         Assert.Equal(HttpStatusCode.OK, res.StatusCode);
     }
     [Fact]
     public async void GetListWithOutParameter()
     {
         var res =await client.GetAsync("api/Content/GetList");
         var values =  JsonConvert.DeserializeObject<List<Content>>(await res.Content.ReadAsStringAsync());

         res.EnsureSuccessStatusCode();

         Assert.Equal(HttpStatusCode.OK,res.StatusCode);
         Assert.Equal(1, values.Count);
     }
     [Fact,Priority(10)]
     public async void Delete()
     {
         var res = await client.GetAsync("api/content/delete/" + DefaultFirstItemId);
         Assert.Equal(HttpStatusCode.OK, res.StatusCode);
     }
 }

resim xunit version: 2.42 .net version: 7.0.4

asherber commented 12 months ago

Thanks for the detailed report! I'll take a look at this later today.

asherber commented 12 months ago

I'm not able to reproduce this. Here's the class I'm using:

[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
[DefaultPriority(0)]
public class TestClass
{
    [Fact, PriorityAttribute(10)]
    public void Foo()
    {
        Console.WriteLine("third");
    }

    [Fact, PriorityAttribute(-10)]
    public void Bar()
    {
        Console.WriteLine("first");
    }

    [Fact]
    public void Baz()
    {
        Console.WriteLine("second");
    }
}

All three tests run for me, in the correct order. Is it possible you have some filter on your test runner that is preventing your Delete() test from running? Are you able to put together a test class that reproduces the issue that doesn't have a dependency on your server code?

sarowa36 commented 12 months ago

Oh sorry mate thats error about my spaggetti code.