Execution Order Issue with ReSharper Test Runner Impacting Tests Individually

I am reaching out to seek assistance regarding an execution order issue we have encountered when using the ReSharper Test Runner. In our C# project, we have implemented a comprehensive test suite that incorporates both unit and integration tests. To ensure proper data setup and deletion, we utilize the [ClassInitialize] attribute in some test classes to perform these tasks before any tests within the class are run. Additionally, for most test classes, we rely on the [TestInitialize] attribute to initialize the test-specific data. However, when running tests through the ReSharper Test Runner, the execution order is not respected. This leads to a critical problem where a test using the [TestInitialize] attribute can inadvertently delete the required data set up by the [ClassInitialize] method. Consequently, the test classes relying on [ClassInitialize] start to fail when subsequent tests run. This issue remains unnoticed when using the Visual Studio Test runner which respects the expected execution order. How can we resolve this execution order problem without having to rewrite many tests for the developers using R#? Is there any configuration or setting within ReSharper that can enforce the correct execution order of tests. Since this is a legacy project we are uncertain about the specific trigger that led to this problem. I have tried it with several older versions of R# but the problem remains.
0
5 comments

Hello Gabriel,
 
When using AssemblyInitializeClassInitialize  or TestInitialize attributes, MSTest has an established order in which it runs the methods marked with such attributes, it is listed in the docs:

The order that methods will be run is:

  1. Methods marked with the AssemblyInitializeAttribute.
  2. Methods marked with the ClassInitializeAttribute.
  3. Methods marked with the TestInitializeAttribute.
  4. Methods marked with the TestMethodAttribute.

In turn, ReSharper runs tests in a class in the order these tests are written in the file, from top to bottom. Hopefully, this information will help point you in the right direction.
 
If you have any further questions, please feel free to ask. We would really appreciate an example of code that produces this behavior as it will enable us to investigate further. Thank you in advance. Have a great day!

 
0

Hello Ivan,

Thank you for your reaction. I have a small video clip (mp4) where you can see the ReSharper Test Runner jump from test to test in different classes. Unfortunately due to the sensitive nature of this project (federal government), I cannot publicly post the video clip. Is there another way for me to share the clip with you?

Thank you,

 

0

Hello,

you can share privately it via another ticket you have submitted earlier (#5223705) or you can use JetBrains Upload Service - upload the file and post the upload ID here.

0

I uploaded the video clip using the JetBrains Upload Service:
Upload id: 2023_06_13_DJ9gypvDQDgmXGFLh8UimS (file: 2023-06-13_12-04-06.mp4)

I indeed submitted a similar ticket a couple of days ago but I could no longer find it and therefore I was under the impression that it never got posted or that it got deleted.

0

Hello,

Thank you for the screencast, it sheds a little light on the behavior you're observing but still - we would really appreciate a sample solution or an example of a test class where the execution order is perceived wrong. Also, do all those tests that are executed in the order show in the video belong to the same test project? 

0

Please sign in to leave a comment.