1

I am using VS 2019 with a unit testing project. I have about 80 tests in total, split across several test classes. I have noticed that when a class has several methods, that the first test takes 30ms or so to run and the others are 1ms or so. These are very cheap tests, hitting no database. And this is very consistent - of my 10 or so test classes, they all exhibit one test method taking substantially longer than others to run.

I've reproduced this with an extremely basic test:

Imports Xunit

Public Class TestTestsCopy

    Property x As Integer

    Public Sub New()
        x += 1
    End Sub

    <Fact()>
    Public Sub TestOne()       
        x += 1

        Assert.Equal(2, x)
    End Sub

    <Fact()>
    Public Sub TestTwo()       
        x += 2

        Assert.Equal(3, x)
    End Sub

    <Fact()>
    Public Sub TestThree()   
        x += 3

        Assert.Equal(4, x)
    End Sub

    <Fact()>
    Public Sub TestFour()     
        x += 4

        Assert.Equal(5, x)
    End Sub
End Class

I also copy/pasted this test and renamed the class - both test classes show the first method taking 33-36ms, and every other test is 1ms.

I know that these timings aren't crazy long but it just looks really odd.

To rule out anything about my projects, I created a brand new 'console app' project with only references to xunit/xunit VS runner, and copied the same test classes as above - exact same behaviour.

VS 'test explorer' showing test timings

Steven Sproat
  • 4,398
  • 4
  • 27
  • 40

0 Answers0