mspec

How do I enforce test isolation in MSpec when static members/methods are required?

回眸只為那壹抹淺笑 提交于 2019-12-12 12:10:25
问题 Ok. I'm trying to wrap my head around why MSpec uses static methods / variables. (Well not exactly static methods, but with member variable delegates, it's practically the same). This makes it impossible to reuse contexts. That or go through and make sure all static variables are reset manually. This has no enforcement on test isolation. If one test sets up some variables and the next one checks for it, it'd pass when it shouldn't. This is starting to get very annoying. What I do in one

How do I run MSpec test assemblies in parallel?

微笑、不失礼 提交于 2019-12-12 08:55:33
问题 We have the following setup: Team City v8.1.2 .NET 2013 Solution with several different C# projects (ASP.NET MVC, libraries, testing projects, etc.) 95% of our tests are MSpec, but we also have some NUnit tests. We have 14 test projects and growing... Currently the testing phase is taking, roughly, 9 minutes for MSpec tests and 1 minute for NUnit. We would like to start parallelizing this, as we expect the number of tests to grow quickly. What would be the best solution, provided that: MSpec

MSpec Test Adapter with TFS

只谈情不闲聊 提交于 2019-12-11 07:53:51
问题 Has anyone successfully used the MSpec Test Adapter with TFS? If yes, can you please shed some light on how I would go on about doing this? I noticed this post but it uses the console runner. 回答1: After lots of research and trial and error, I finally figured how to make this work. It's actually pretty easy. Install the MSpec Test Adapter on the build server. Download the MSpec Test Adapter and change the file type to .zip Extract the files to a folder on your build server. Point the "Version

How to write specs with MSpec for code that changes Thread.CurrentPrincipal?

独自空忆成欢 提交于 2019-12-11 07:29:39
问题 I've been converting some old specs to MSpec (were using NUnit/SpecUnit). The specs are for a view model, and the view model in question does some custom security checking. We have a helper method in our specs which will setup fake security credentials for the Thread.CurrentPrincipal. This worked fine in the old unit tests, but fails in MSpec. Specifically, I'm getting this exception: "System.Runtime.Serialization.SerializationException: Type is not resolved for member" It happens when part

Why do I get an Invalid Operation Exception (non STA thread?) running this MSpec test on TeamCity?

↘锁芯ラ 提交于 2019-12-10 22:55:28
问题 As part of the migration of my app to .NET 4, I'm struggling to get some of the WPF unit tests working again with TeamCity. On all the tests that are somehow using a WPF control (a ListItem for example), I get an exception I didn't get before: System.InvalidOperationException: The calling thread must be STA, because many UI components require this. I understand what it means, and after checking, it turns out that my thread is indeed MTA, not STA. My problem is that I have no idea on how to

Why is this inherited Establish executed multiple times?

时间秒杀一切 提交于 2019-12-10 16:52:21
问题 My understand is that each Establish should only be executed once, but the code below shows it executing multiple times. We're nesting the classes to provide some grouping while keeping the unit tests for a Subject in one file. This seems like it is a bug. We're using the machine.specifications.runner.resharper Reshaper extension and MSpec 0.9.1. [Subject(typeof(string))] internal class EstablishRunTwice { Establish sharedContext = () => Console.WriteLine("Shared context"); internal class

MSpec: How to make static variables thread-safe?

拈花ヽ惹草 提交于 2019-12-10 15:20:57
问题 I'm using MSpec for my latest project, and overall I'm really happy with it. However, I do have an issue with concurrency when my tests run in paralel and I'm wondering if anybody has run into this issue or, even better, has a solution? MSpec heavily relies on static methods and variables to work. Now it appears when I define static variables in my base classes, that are used by multiple test classes, and I run my tests in paralel, that they share the same static variables and thus interfere

How do I run setup and teardown code with each test in MSpec?

坚强是说给别人听的谎言 提交于 2019-12-09 15:37:55
问题 I have generic code for setting up and tearing down NHibernate, which I need on pretty much all my tests. Is there a way to include the 'need for all tests' code in one place, then have it applied to all tests? (ie like Nunit's setup and teardown methods) [Subject("Accessing the TAE allocation page")] public class when_a_request_to_the_tae_allocation_page_is_made { Establish context = () => NHTestHelper.StartTest(); //need for all tests Because of = () => result = new AllocationController

Why do I get a NullReferenceException when testing this async method with MSpec/Moq?

怎甘沉沦 提交于 2019-12-07 13:58:13
问题 I want test if the correct type is returned from an async method. This method uses another async method in a dependency class. The dependency class implements this interface: Task<string> DownloadStringAsync(string url); The method I want to test is this: public async Task<T> GetData<T>(string url) where T : class , new() { var jsonData = await _webClientWrapper.DownloadStringAsync(url); if (string.IsNullOrEmpty(jsonData)) return new T(); try { return await JsonConvert.DeserializeObjectAsync

DRY-ing very similar specs for ASP.NET MVC controller action with MSpec (BDD guidelines)

人盡茶涼 提交于 2019-12-07 05:34:18
问题 I have two very similar specs for two very similar controller actions: VoteUp(int id) and VoteDown(int id). These methods allow a user to vote a post up or down; kinda like the vote up/down functionality for StackOverflow questions. The specs are: VoteDown: [Subject(typeof(SomeController))] public class When_user_clicks_the_vote_down_button_on_a_post : SomeControllerContext { Establish context = () => { post = PostFakes.VanillaPost(); post.Votes = 10; session.Setup(s => s.Single(Moq.It.IsAny