nunit

nUnit Assert.That(method,Throws.Exception) not catching exceptions

时光怂恿深爱的人放手 提交于 2019-12-20 15:45:04
问题 Can someone tell me why this unit test that checks for exceptions fails? Obviously my real test is checking other code but I'm using Int32.Parse to show the issue. [Test] public void MyTest() { Assert.That(Int32.Parse("abc"), Throws.Exception.TypeOf<FormatException>()); } The test fails, giving this error. Obviously I'm trying to test for this exception and I think I'm missing something in my syntax. Error 1 TestCase '.MyTest' failed: System.FormatException : Input string was not in a correct

How to integrate NUnit tests into a TFS 2010 build

橙三吉。 提交于 2019-12-20 12:06:50
问题 What is the best way to integrate nunit tests into TFS 2010? Is it via generic tests or is there a better approach to running them? Ideally I'd like to have the granularity of one generic test per test assembly and have a way to surface the results in the TFS build report. 回答1: You can run nunit tests from command line and therefore you can automate these tests via your (Workflow) build template. Since there aren't a lot of custom build activities available for TFS 2010 yet, you could write

NUnit Categories in combination?

假装没事ソ 提交于 2019-12-20 11:20:32
问题 In my NUnit testfixtrues i have something along the lines of [Test,Category("catA")] public void test1 { // } [Test,Category("catB")] public void test2 { // } [Test,Category("catA")] [Test,Category("catB")] public void test3 { // } Now in the NUnit gui i want to be able to select catA and catB and run the tests where catA and catB are present. Currently this is not the case and NUnit will run all 3 tests. Is there any way to change this behavior to an AND condition rather than OR? I'm

Unit testing with Moq, Silverlight and NUnit

青春壹個敷衍的年華 提交于 2019-12-20 10:41:31
问题 I am attempting to unit test a Silverlight 3 project. I am using: Moq.Silverlight (3.0.308.2) NUnitSilverlight (http://www.jeff.wilcox.name/2009/01/nunit-and-silverlight/) When I write a test that does not use Moq, it works as it should. When I use Moq outside of a test, Moq works as it should. (I mocked a interface and did a verify in a button handler as a proof.) But when I run a unit test that uses Moq, I always get this: System.IO.FileNotFoundException: Could not load file or assembly

Unittest SignalR Hubs

别等时光非礼了梦想. 提交于 2019-12-20 10:27:48
问题 I Would like to test my Hub in SignalR, what is the best approach? Possible solutions I have thought about so far: Create a testable Hub Abstract logic to separate class Selenium (would like to test smaller units) Or is it some SignalR testing features have overlooked Currently using SignalR 0.4, and NUnit as the testing framework. 回答1: This link shows how to unit test SignalR hub methods using Moq. You mock up the respository, clients, context, and the caller. Here's the code from the site,

Testing for exceptions with [TestCase] attribute in NUnit 3?

谁都会走 提交于 2019-12-20 10:19:49
问题 How do I test for exceptions in a TestCase with NUnit3? Let's say I have a method Divide(a,b) defined as follows: public double Divide(double a, double b) { if(Math.Abs(b) < double.Epsilon) throw new ArgumentException("Divider cannot be 0"); return a/b; } I want to test this method using NUnit 3.0 test cases, so maybe I have: [TestCase(-10, 2, -5)] [TestCase(-1, 2, -0.5)] public void TestDivide(double a, double b, double result) { Assert.That(_uut.Divide(a, b), Is.EqualTo(result)); } Is there

How to do internal interfaces visible for Moq?

时间秒杀一切 提交于 2019-12-20 09:57:27
问题 I have 3 project in my C# solution. Signatures Structures Tests Signatures has public and internal interfaces. Also it has [assembly: InternalsVisibleTo("Structures")] [assembly: InternalsVisibleTo("Tests")] in AssemblyInfo.cs of. Structures has public and internal classes and [assembly: InternalsVisibleTo("Tests")] in AssemblyInfo.cs of. Tests has next source: <packages> <package id="Moq" version="4.2.1409.1722" targetFramework="net45" /> <package id="NUnit" version="2.6.4" targetFramework=

NUnit assembly not found

﹥>﹥吖頭↗ 提交于 2019-12-20 09:55:13
问题 I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under Program Files , and I keep getting this error when trying to load my tests. Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The system cannot find the file specified** In order to simplify the problem, I've compiled the most basic possible test file. using NUnit.Framework; namespace test {

Using WPF components in NUnit tests - how to use STA?

非 Y 不嫁゛ 提交于 2019-12-20 09:47:38
问题 I need to use some WPF components in an NUnit unit test. I run the test through ReSharper, and it fails with the following error when using the WPF object: System.InvalidOperationException: The calling thread must be STA, because many UI components require this. I've read about this problem, and it sounds like the thread needs to be STA, but I haven't figured out how to do this yet. What triggers the problem is the following code: [Test] public void MyTest() { var textBox = new TextBox();

Using WPF components in NUnit tests - how to use STA?

泪湿孤枕 提交于 2019-12-20 09:47:11
问题 I need to use some WPF components in an NUnit unit test. I run the test through ReSharper, and it fails with the following error when using the WPF object: System.InvalidOperationException: The calling thread must be STA, because many UI components require this. I've read about this problem, and it sounds like the thread needs to be STA, but I haven't figured out how to do this yet. What triggers the problem is the following code: [Test] public void MyTest() { var textBox = new TextBox();