在使用NUnit和XML注释编写C#代码时,哪种格式是必需的,还是首选格式?
将:
using NUnit.Framework;
namespace FooBar{
/// <summary>
/// The <c>foo</c> class tests bar
/// </summary>
[TestFixture]
public class Foo{
}
}
是正确的或将:
using NUnit.Framework;
namespace FooBar{
[TestFixt
编辑:问题修订。
我正在将几个测试从nUnit迁移到xUnit,我有一个问题:重新分级SetFixture()方法和构造函数之间的关系。我的测试有常见的设置方法。根据xUnit手册,[Setup]代码现在应该进入构造函数。考虑一下这个例子:
public class MyTestClass : IUseFixture<TestFixture> {
private TestObject m_MyObject;
public MyTestClass() {
m_MyObject.Login()
}
public void SetFi
我有一个问题,NUnit告诉我:“找不到合适的构造函数”。这是什么原因造成的?我还收到另一条消息:"Exception I a stacktrace“。这两条信息只是一遍又一遍地重复。这是我的代码
[TestFixture]
public class SecurityServiceTests
{
private IContext stubIContext;
private ISecurityService securityService;
private IWindsorContainer windsorContainer;
public Securi
有没有办法为列表中的每一项运行一次nunit TestFixture?假设我有一个类似如下的设置: Public Class TestData
{
Public String Parameter1{get;}
Public String Parameter2{get;}
Public String Parameter3{Get;}
} 我想要做的是创建一个TestData对象列表: List<TestData> inputs = new List<TestData>(){}; 然后使用nunit 3,对列表中的每个项目运行一个TestFixture和其中包含的所有测试
如何绕过您想要定义的TestFixture需要引用没有无arg构造函数的类型的场景?
我正在尝试测试一个具有多个实现的接口。从NUnit文档中,它展示了如何使用这样的泛型来设置它(在这里,我可以定义多种实现类型):
[TestFixture(typeof(Impl1MyInterface))]
[TestFixture(typeof(Impl2MyInterface))]
[TestFixture(typeof(Impl3MyInterface))]
public class TesterOfIMyInterface<T> where T : IMyInterface, new()
我正在Visual 2013 Professional中实现一个测试解决方案。我选择了NUnit (版本2.6.4)作为测试框架。为了在Visual中执行测试,我已经安装了NUnit测试适配器。一切正常工作,直到我输入一个NUnit扩展类来获得断言失败消息.在中的该类实现之前,正确列出了所有测试类和相关方法;在扩展实现之后,当我重新构建解决方案时,测试列表将不再出现(测试资源管理器窗口是可见的,但当我构建/重新构建解决方案时,没有列出任何列表)。
我的所有类都是public,每个测试类都带有[TestFixture]属性,每个测试方法都带有[Test]属性。在我的扩展课下面:
using Sy
如果我有以下代码:
[TestFixture]
public class MyBaseTest
{
protected ISessionManager _sessionManager;
[SetUp]
public void SetUp() { /* some code that initializes _sessionManager */ }
}
[TestFixture]
public class MyDerivedTest : MyBaseTest
{
IBlogRepository _repository;
[SetUp]
publ
在编写测试时,我发现了一个奇怪的Visual静态分析错误。下面的代码在和FailCA两种测试方法上生成PassCA。
“ClassToTestTests.FailCA()”似乎没有上游的公共或受保护的呼叫者。“ClassToTestTests.PassCA()”似乎没有上游的公共或受保护的呼叫者。
代码:
using System;
using NUnit.Framework;
using static Namespace.ClassToTest;
using static NUnit.Framework.Assert;
namespace Namespace {
publi
我正在为ASP.NET MVC应用程序在C#中使用NUnit创建单元测试。
短版本:是按字母顺序还是按属于被测试类的方法的顺序排序?
例如,:说我想测试这个类:
public class MyClass{
public void B(){}
public void A(){}
public void C(){}
}
如果我把我的考试课程安排成这样更合适.
[TestFixture]
public class MyClassTests{
[Test]public void Test_B(){}
[Test]public void
我正在测试一个类的方法。然而,它们中的一些属性做了一些不相关的事情,这使得测试失败。
例如,我有这样一个类(在VB.net中,但也可以是C# )
<AttributeOne()>
<AttributeTwo(Arg1, Arg2)>
Public Overridable Function SomeMethod() As Object
' Stuff
End Function
当我从我的模拟对象调用SomeMethod时,它会引发一些异常,因为属性试图做一些在单元测试上下文中不可能做的事情。
[TestFixture]
public class SomeCl
我对NUnit有一个问题--不知道有没有人有什么想法。
我们使用的是NUnit 2.5.3.9345和C# 3.5。
使用以下代码:
public class UnitTestBase
{
[TestFixtureSetUp]
public void SetUpTestFixture()
{
//Do something in base
}
}
[TestFixture]
public class SomeTestClass : UnitTestBase
{
[TestFixtureSetUp]
public void Fixt
我在使用C#中的COM类时遇到了问题。COM类是用32位C++ ATL语言开发的。
当我从VBA、VB6、C++、Javascript甚至从MSTest/C#使用COM类时,它工作得很好。
奇怪的是,当我从NUnit-test或控制台应用程序创建实例时,它会失败,并出现异常:
System.InvalidCastException : Unable to cast COM object of type 'PvtsFlashLib.FlashClass' to interface type 'PvtsFlashLib.IFlash4'. This operatio
我有一个nunit 2.5.10参数化测试:
[TestFixture(parameter1)]
[TestFixture(parameter2)]
public class MyTest : BaseTest
{
var param="";
public MyTest(string arg)
{
param=arg;
}
[Test]
public Test()
{
//... test stuff
}
}
在VS12withReSharper7.0.1中,我只运行一个,但是!
我们使用VS 2008和ReSharper5.1 (C#)和NUnit 2.4.8。
我有一个基本的测试类,它做而不是,它有一个[TestFixture]属性:
public class BaseTestCasesFixture: BaseFixture
{
protected virtual int Calculate(DatePeriod period)
{
throw new NotSupportedException("Should be implemented by inheriter");
}
[Test]
我正在尝试让nunit和autofac协同工作,以实现Selenium测试框架。
我理解为什么会出现OneTimeSetUp: No suitable constructor was found错误(因为如果nunit有一个不为空的ctor,它就不能启动UnitTest1 ),但是我不知道如何解决这个问题。
这似乎是一个先有鸡还是先有蛋的问题;nunit需要IHomePage才能运行测试,但容器并未创建,因为直到测试开始运行时才会调用SetUp或OneTimeSetUp。
[TestFixture]
public class UnitTest1
{
IH
我对C#和nunit非常陌生。请容忍我,如果这是基本的,并已在这里被问到。
我们有一个全局设置,由SetupFixture类定义,预计只运行一次。私有变量在它的设置中定义。我们希望在所有的testfixture中使用相同的变量,从而在所有的testfixture中继承testbase类。但是,在执行Testcase1时,我观察到globalSetup()被多次调用。谁能给我指出问题所在?示例代码如下。
namespace CTB
{
[SetupFixture]
public class Testbase
{
下面是一个简单有效的测试:
module Tests
open NUnit.Framework
open FsUnit
[<TestFixture>]
type simple ()=
[<Test>] member test.
``tautology`` ()=
true |> should be True
我的项目还没有使用F#的任何面向对象的特性--我可以在没有对象的情况下编写测试吗,或者这只是NUnit的工作方式?
我现在正在尝试第一次学习NUnit。 对于我想要使用测试驱动程序开发的C#程序,我决定首先编写一个User类。这个User类(在语义上)将如下所示: using System;
namespace SSH_file_drop
{
public class User
{
private Boolean authenticated = false;
public string userName = null;
//one-time object 'transmission' instance to allow
我目前正在使用C#、nunit和Selenium构建一个自动化项目,我正在尝试创建一个安装类,它将在任何TestFixture运行之前初始化selenium webdriver,并且在所有这些设置结束之后,尝试在每个TestFixture OneTimeSetUp属性中从TestFixture中获取webdriver,可以这样做吗?或者我应该将selenium类更改为static,以便能够在每个TestFixture设置中获得driver字段吗?
所以基本结构是这样的:
[SetUpFixture]
public class Test
{
[OneTimeSetUp]
publ
我试图在Visual中的测试中使用NUnit超时值属性,但它似乎不起作用。我希望这个测试失败,但是它却运行了20秒,然后通过了测试。
为什么不失败呢?
namespace Tests
{
using System.Threading;
using NUnit.Framework;
[TestFixture]
public class timeout_tests
{
[Test, Timeout(1)]
public void timeout_test()
{
Thread.Slee
我在visual studio中使用selenium编写了一个简单的测试,它可以在Firefox中工作。然而,我试图在多个浏览器上运行相同的测试,但我总是得到相同的错误,即在目录或PATH环境变量中找不到驱动程序。我已经下载了它们,它们在我正在工作的项目中。我已经尝试了所有不同的方法,但都不起作用。有人能帮上忙吗?谢谢:)
下面是一段代码:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Open
我有一个简单的解决方案,我放入了一个c#类库项目,并引用了nunit dll等。
我创建了一个.cs文件,添加了测试装置和一个简单的测试
如果我转到测试->,在当前上下文中运行->测试(甚至在解决方案中运行所有测试)
我得到了错误:
No tests were run b/c no tests are loaded or the selected tests are disabled.
我确实编译了这个项目。
SomeTest.cs
using System.Collections.Generic;
using System.Linq;
using System.Text;
usi