How to write unit tests with TPL and TaskScheduler

后端 未结 5 1555
离开以前
离开以前 2021-02-01 06:50

Imagine a function like this:

private static ConcurrentList list = new ConcurrentList();
public void Add(object x)
{
   Task.Factory.         


        
      
      
      
5条回答
  •  北恋
    北恋 (楼主)
    2021-02-01 07:14

    A colleague of mine and I are building a unit testing framework which addresses TPL and Rx testing, and there is a class which you could leverage to replace the default TaskScheduler in a testing scenario, so that you don't need to modify your method signatures. The project itself isn't published yet, but you can browse the file here nonetheless:

    https://github.com/Testeroids/Testeroids/blob/master/solution/src/app/Testeroids/TplTestPlatformHelper.cs

    The work of setting up the task scheduler is done in TplContextAspectAttribute.cs.

提交回复
热议问题