天道酬勤,学无止境

nunit

How do you disable PostSharp when running unit tests?

I want my nunit tests not to apply any of my PostSharp aspects so I can test my methods in isolation. Can this be done somehow in the Test Fixture Setup, or can it only be done on a per project level?

2022-01-19 02:34:35    分类:问答    c#   unit-testing   nunit   aop   postsharp

Partial Code Coverage C# - Nunit

I have partial code coverage and I don't know why. for people who like the question before they start reading Want to start by saying "First Post" as well as I am still very Junior in my development career but I have been a relativly quick learner(imo), so here it goes. Using Nunit to test, and MVP based. Code to be tested - void _view_Delete(object sender, EventArgs<Guid> e) { _agRepo.Delete(_agRepo.GetByID(e.Value)); var g = _agRepo.GetAll(); if (g.Count() > 0) { _view.FillRelatableAccessGroups(g.Where(x => x.IsRelatable));//partial coverage _view.FillStandAloneAccessGroups(g.Where(x => !x

2022-01-18 11:26:38    分类:问答    c#   visual-studio-2010   unit-testing   nunit   code-coverage

Expect exceptions in nUnit without the ExpectedException attribute

I have methods with more than one parameter that are guarded against bad input by throwing ArgumentNullExceptions and ArgumentExceptions whenever any parameter is null. So there are two obvious ways to test this: One test per Parameter using the [ExpectedException] attribute One test for all parameters using multiple try{} catch blocks The try catch thing would look like that: try { controller.Foo(null, new SecondParameter()); Assert.Fail("ArgumentNullException wasn't thrown"); } catch (ArgumentNullException) {} With one little problem. If the test passes, Assert.Fail never gets called and

2022-01-18 11:25:53    分类:问答    unit-testing   exception   nunit

How to make WebBrowser complete navigation when running in a headless unit test?

We have a WPF application that loads some content in a <WebBrowser/> control and then makes some calls based on what was loaded. With the right mocks, we think we can test this inside a displayless unit test (NUnit in this case). But the WebBrowser control doesn't want to play nicely. The problem is that we never receive the LoadCompleted or Navigated events. Apparently this is because a web-page is never "Loaded" until it is actually rendered (see this MSDN thread). We do receive the Navigating event, but that comes far too early for our purposes. So is there a way to make the WebBrowser

2022-01-18 11:08:09    分类:问答    c#   wpf   nunit   webbrowser-control

How can I run automated bdd UI tests using NUnit and SpecFlow in particular order driven by categories

I need help running an automated UI tests by Continuous integration. I have around 200 test cases but they are not written following some good practices and they are depending each other. I am a dev not a QA and I don't know what is happening in details so excuse me if i am not right for something. This is what i can see : 1. The tests are BDD 2. They are written with SpecFlow 3. NUnit is used as test executor The system is a bit complicated and it is hard to write tests without dependencies but not impossible the idea is that the person, who has wrote them does not have a good knowledge of

2022-01-18 06:33:33    分类:问答    selenium   nunit   bdd   specflow   qa

NUnit: How to test a private method with "ref"parameter in C#

I have a private method like below: int void SomeMethod(ref string theStr) { // Some Implementation } how to write the unit test case for this method.

2022-01-18 00:47:19    分类:问答    c#   nunit

Very long build time in Visual Studio

I've a solution with 15 projects (14 class libraries and one web application). Each class library has corresponding test project (i.e. if I have MyApp.Services project there exists MyApp.Services.Tests -- using NUnit). Everything is written in VB.NET. The problem is that when VS tries to compile any of *.Tests project it stops responding (the bigger the project the longer the period without reposnse). I don't know where to start looking for an issue. I'll add that I've R# 4.5 installed. UPDATE 1: Is there any way to benchmark a build in visual studio? To get build times for every project

2022-01-17 09:26:14    分类:问答    vb.net   visual-studio   build   nunit

NHibernate SchemaExport not creating table

I'm learning Nhibernate and am making a test project. I want to generate tables based on the entities. In the test project, I am using sqlite and can see the output: "drop table if exists Player" but it's not creating the table Player afterwards. I have confirmed by copying the Player.hbm.xml file into another folder that the mapping is being found. Test class in the test project: [Test] public void TestCanGenerateSchema() { var cfg = new Configuration(); cfg.Configure(); //tell NH to configure itself based on the config cfg.AddAssembly(typeof(Player).Assembly); //find mapping info in this

2022-01-16 22:01:01    分类:问答    c#   hibernate   nhibernate   nunit

如何在另一个线程上正确地对调用 UI 方法进行单元测试?(How to properly unit test calling UI method on another thread?)

问题 编写了扩展方法(基于在单独线程上启动事件处理程序类时的 GUI 更新?): public static class ControlExtensions { public static TResult InvokeEx<TControl, TResult> (this TControl control, Func<TControl, TResult> func) where TControl : Control { if (control.InvokeRequired) return (TResult)control.Invoke (func, control); return func (control); } } 我一直在尝试从 UI 线程和普通线程对这个方法进行单元测试,但我似乎无法实现这一点。 下面是单元测试代码: [Test] public void TestInvokeExWithMethodReturningResultOnOtherThread () { // Prepare string result = string.Empty; var form = new Form (); var thread = new Thread (() => { result = form.InvokeEx (f => f.Text); }); // Execute

2022-01-16 16:56:41    分类:技术分享    .net   multithreading   unit-testing   c#-3.0   nunit

具有参数化单元测试的 .NET 测试框架,每个组合显示红色/绿色?(.NET test framework with parameterized unit testing, that shows red/green for each combination?)

问题 当您有 X 单元测试 * Y 配置时,参数化单元测试非常有用。 我有3 个单元测试,每个测试都必须在5 个特定情况下运行。 我使用 xUnit.net 的Theory / PropertyData功能,效果很好。 问题:在 Test Runner UI 中,每个单元测试都有一个绿色/红色符号,表示3 。 这使得评估进度变得困难:符号为红色,直到所有配置都完美运行。 我想要15 个符号,每个单元测试 * 配置一个,以了解哪个特定组合出错了。 xunit.net 尚未实现显示15 个符号的功能。 我愿意切换到另一个测试框架只是为了获得这个功能。 问题:是否有任何 .NET 测试框架具有此功能? 任何类型的报告都可以(GUI、HTML 等) 回答1 您可以使用 NUnit 的 TestCaseAttribute 或 TestCaseSourceAttribute 来指定不同的测试参数。 每个测试用例将在测试运行器中显示为单独的测试。 回答2 NUnit 控制台会告诉你哪个测试用例失败了。 例子: [TestCase("ABK")] [TestCase("bgba")] [TestCase("CBVS")] [TestCase("DSBH")] [TestCase("E")] [TestCase("FJMC")] [TestCase("HBTV2")] [TestCase(

2022-01-16 16:55:31    分类:技术分享    c#   unit-testing   nunit   xunit.net   parameterized-unit-test