How to run unit tests in STAThread mode?

后端 未结 4 625
醉话见心
醉话见心 2020-12-03 00:46

I would like to test an app that uses the Clipboard (WindowsForms) and I need the Clipboard in my unit tests also. In order to use it, it should run in STA mode, but since

4条回答
  •  抹茶落季
    2020-12-03 01:00

    In NUnit 2.6.1+ you can use the /apartment=STA command line flag:

    NUnit-Console version 2.6.3.13283
    Copyright (C) 2002-2012 Charlie Poole.
    Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
    Copyright (C) 2000-2002 Philip Craig.
    All Rights Reserved.
    
    Runtime Environment -
       OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
      CLR Version: 4.0.30319.18052 ( Net 4.5 )
    
    
    NUNIT-CONSOLE [inputfiles] [options]
    
    Runs a set of NUnit tests from the console.
    
    You may specify one or more assemblies or a single
    project file of type .nunit.
    
    Options:
    ...
    /apartment=X            Apartment for running tests: MTA (Default), STA
    ...
    

提交回复
热议问题