nunit

How to correct write test with async methods?

末鹿安然 提交于 2020-01-02 14:33:27
问题 I have class for iterating images. public class PictureManager { private int _current; public List<BitmapImage> _images = new List<BitmapImage>(5); public static string ImagePath = "dataImages"; public async void LoadImages() { _images = await GetImagesAsync(); } public async Task<List<BitmapImage>> GetImagesAsync() { var files = new List<BitmapImage>(); StorageFolder picturesFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("dataImages"); IReadOnlyList<IStorageItem> itemsList =

How to correct write test with async methods?

筅森魡賤 提交于 2020-01-02 14:32:02
问题 I have class for iterating images. public class PictureManager { private int _current; public List<BitmapImage> _images = new List<BitmapImage>(5); public static string ImagePath = "dataImages"; public async void LoadImages() { _images = await GetImagesAsync(); } public async Task<List<BitmapImage>> GetImagesAsync() { var files = new List<BitmapImage>(); StorageFolder picturesFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("dataImages"); IReadOnlyList<IStorageItem> itemsList =

How to correct write test with async methods?

我与影子孤独终老i 提交于 2020-01-02 14:31:45
问题 I have class for iterating images. public class PictureManager { private int _current; public List<BitmapImage> _images = new List<BitmapImage>(5); public static string ImagePath = "dataImages"; public async void LoadImages() { _images = await GetImagesAsync(); } public async Task<List<BitmapImage>> GetImagesAsync() { var files = new List<BitmapImage>(); StorageFolder picturesFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("dataImages"); IReadOnlyList<IStorageItem> itemsList =

Run NUnit tests automatically from command line

我与影子孤独终老i 提交于 2020-01-02 07:23:26
问题 I'm launching the NUnit gui from visual studio by setting the test project to start start nunit 2.5.3 as an external program. That loads the tests into the GUI but I still have to manually click the run button. Is there a command line argument that will have the tests run at the same time they're loaded? 回答1: Specify /run on the command line. 回答2: Help Syntax NUNIT-GUI [inputfile] [options] Runs a set of NUnit tests from the console. You may specify an assembly or a project file of type

How can I display more info in an error message when using NUnit Assert in a loop?

↘锁芯ラ 提交于 2020-01-02 01:18:07
问题 Consider the following code: [Test] public void WidgetTest() { foreach (Widget widget in widgets) { Assert.AreEqual(0, widget.SomeValue); } } If one of the asserts fails, I will get a very unhelpful error message like the one below: 1) Test Failure : WidgetTest.TestSomeValue Expected: 0 But was: 1 at WidgetTest.TestSomeValue() So, the question is, how can I get NUnit to display more useful info, such as the name of the widget, or the iteration of the loop, etc? Even a line number would be

How to unit-test a class which needs a specific file to be present

百般思念 提交于 2020-01-02 01:15:16
问题 I'm currently trying to learn proper unit-test. So now I'm trying to write unit-tests for a class that should map data from an XML-File to the proper objects. Of course all functionality of the class is dependent on the existence of the corresponding XML-file. The XML-file is loaded in the constructor of the class. I'm using C# with NUnit. So far I've got two tests: [Test] public void ShouldAllowInstanceToBeCreatedWhenXMLFileIsPresent() { if (File.Exists(SettingsReader.XML_SETTINGS_PATH)) {

How to initialize ConnectionStrings collection in NUnit

社会主义新天地 提交于 2020-01-01 10:56:11
问题 I want to test ASP.NET application using NUnit, but it seems WebConfigurationManager.ConnectionStrings collection is empty when running from NUnit GUI. Could you tell me how to initialize this collection (probably in [SetUp] function of [TestFixture])? Should I copy Web.config somethere? Thank you! 回答1: If you have your unit-test assembly named Company.Component.Tests.dll, then just make sure that Company.Component.Tests.dll.config is there with the proper connection string. Additionally, it

NUnit async test causing AppDomainUnloadedException

為{幸葍}努か 提交于 2020-01-01 09:58:11
问题 I have a .NET 4.5 WCF service with async operations. I have integration tests which constructs the service host using NetNamedPipeBinding and hits the operation via a client. However, each test like this always causes NUnit to report the following: System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion. Everything looks

When running NUnit and specifying a category, can all uncategorized tests be included too?

荒凉一梦 提交于 2020-01-01 09:38:11
问题 We have several hundred test classes, with a few dozen of them marked with the following attributes: [TestFixture] [Explicit] [Category("IntegrationTests")] so they will only be run in our over-night automated build. The remaining TestFixtures don't have a Category specified (and are not marked Explicit either). Here is the NAnt task we are running to execute our tests: <nunit2> <test> ... <categories> <include name="IntegrationTests" /> </categories> ... </test> </nunit2> This, of course,

Are Custom Filters in NUnit Possible?

谁说胖子不能爱 提交于 2020-01-01 09:04:12
问题 Is it possible to define a custom filter so that NUnit will only run specific tests? I have many of my Nunit tests marked with a custom attribute "BugId". Is it possible to write a filter so that I can pass in a number and only run the tests with that attribute and number? If so show mockup or real code. 回答1: Do the filters need to use your custom attribute, or could you use an NUnit Category? Something like [Test] [Category("BugId-12234")] public void Test() { .... } ... and then use the