Tag: nunit

依赖项目之间不依赖的依赖关系,导致System.IO.FileNotFoundException

假设我的解决方案有两个项目: 第一个叫做“MainProject”(一个.NETStandard 2.0项目)。 第二个称为“MainProjectTests”(一个NUnit测试项目),每个类的一些unit testing进入“MainProject”。 第一个项目(MainProject)有一个名为“dependencyX”的NuGet依赖项。 显然,项目“MainProjectTests”引用了“MainProject”。 因此,当测试运行器运行“MainProjectTests”测试时,使用“dependencyX”从“MainProject”调用方法,我得到一个System.IO.FileNotFoundExceptionexception: System.IO.FileNotFoundException:无法加载文件或程序集’dependencyX,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null’或其依赖项之一。 为什么我得到这个例外? 当我将“dependencyX”添加到“MainProjectTests”时,一切正常,但在我看来,这不是一个好习惯……如何解决? 我正在使用Visual Studio for Mac Community 7.2预览版(7.2 build 583) 谢谢您的帮助。 编辑: 尝试选择: PackageReference true 在NUnit项目中,但获得相同的结果。

unit testing自定义ConfigurationElement和ConfigurationElementCollection

我创建了一个自定义ConfigurationElement和ConfigurationSection ,以便在启动时更轻松地设置一系列应用程序参数。 但是,我真的很想对这个逻辑进行unit testing。 ServiceConnection public class ServiceConnection : ConfigurationElement { [ConfigurationProperty(“locationNumber”, IsRequired = true)] public string LocationNumber { get { return (string) base[“locationNumber”]; } set { base[“locationNumber”] = value; } } [ConfigurationProperty(“hostName”, IsRequired = true)] public string HostName { get { return (string) base[“hostName”]; } set { base[“hostName”] = value; } } [ConfigurationProperty(“port”, IsRequired […]

NUnit示例代码?

我想学习如何使用NUnit。 我通过阅读然后玩真实的代码来学习。 我在哪里可以找到一个以示例性方式使用NUnit的小型简单C#项目?

通过Selenium WebDriver C#获取HTTP状态代码

我正在使用Selenium,C#,NUnit来编写自动化测试。 是否可以使用WebDriver获取HTTP状态代码,以便可以向用户发出因HTTP请求而失败的测试?

NUnit的Is.Equal对于从generics类派生的类不能可靠地工作吗?

今天我遇到了NUnit的以下问题。 我有一个类,派生自generics类。 我开始做一些序列化测试,并使用NUnit的Is.EqualTo()函数测试相等性。 当一个应该失败的测试通过时,我开始怀疑出现了问题。 当我使用obj1.Equals(obj2)而不是它应该失败时。 为了调查我创建了以下测试: namespace NUnit.Tests { using Framework; public class ThatNUnit { [Test] public void IsNotEqualTo_ClientsNotEqual_Passes() { var client1 = new DerrivedClient(); var client2 = new DerrivedClient(); client1.Name = “player1”; client1.SomeGenericProperty = client1.Name; client2.Name = “player2”; client2.SomeGenericProperty = client2.Name; Assert.That(client1.Equals(client2), Is.False); Assert.That(client1, Is.Not.EqualTo(client2)); } [Test] public void IsNotEqualTo_ClientsAreEqual_AlsoPasses_SomethingWrongHere() { var client1 = […]

NSubstitute – TestFixture 1在TestFixture 2中导致AmbiguousArgumentsException

我正在使用NUnit和NSubstitute编写C#unit testing。 我正在测试一个类,它将尝试从实现以下接口的配置提供程序中检索对象: public interface IConfigProvider { T GetConfig(int id); T GetConfig(string id); } 正在测试的类只使用了GetConfig的int版本,因此在SetUpFixture中我执行以下操作来设置一个总是返回相同虚拟对象的模拟配置提供程序: IConfigProvider configProvider = Substitute.For<IConfigProvider>(); configProvider.GetConfig(Arg.Any()).Returns(new ConfigType(/* args */); 如果TestFixture是唯一运行的TestFixture,则运行绝对正常。 但是,在同一个程序集中的不同TestFixture中,我检查接收到的调用如下: connection.Received(1).SetCallbacks(Arg.Any<Action>(), Arg.Any<Action>(), Arg.Any<Action>()); 如果这些Received测试在配置提供程序测试之前运行,则配置测试在SetUpFixture中失败并出现AmbiguousArgumentsException: Here.Be.Namespace.ProfileManagerTests+Setup (TestFixtureSetUp): SetUp : NSubstitute.Exceptions.AmbiguousArgumentsException : Cannot determine argument specifications to use. Please use specifications for all arguments of the same type. at NSubstitute.Core.Arguments.NonParamsArgumentSpecificationFactory.Create(Object argument, IParameterInfo […]

使用NUnit测试Windows 8商店应用程序

我目前正在为一个类的Windows应用程序应用程序(Windows 8)工作,我在运行NUnit测试时遇到问题。 我的解决方案/项目设置如下所示: TheMetroApp.sln SQLite-net.csproj – 类库(Windowsapp store应用)。 文件从NuGet中提取。 DataModel.csproj – 类库(Windowsapp store应用) UnitTests.csproj – unit testing库(Windowsapp store应用)。 NUnit框架是从NuGet中提取的。 TheMetroApp.csproj – 从其中一个Windows SDK示例中提取的项目文件。 杂项。 依赖性和实用性 Windows 8 Pro RTM / Visual Studio 2012 RTM ReSharper 7 NUnit 2.6.1 SQLite(根据此处的说明设置) UnitTests依赖于并引用DataModel。 DataModel依赖于并引用SQLite-net。 我添加到UnitTests项目的唯一内容是包含一些存根NUnitunit testing的单个类。 据我所知,这些设置正确: [TestFixture] public class TaskSourceTests { #region Private Class Members private ITaskSource […]

如何从命令提示符执行NUnit测试用例

如何使用NUnit从Command Console执行测试用例? 我有一套基于NUnit框架用C#编写的Selenium Tests。 我只需要从命令控制台运行就可以执行测试用例。 在JUnit中,我们可以从cmd运行测试用例 java junit.swingui.TestRunner test.Run 我们怎么能在NUnit上面做?

C#,NUnit在循环中断言

我有一个学校作业,我需要创建一个数据驱动的NUnit测试风格。 使用下面的代码,我可以从数据库中获取数据,但每次’Assert’调用失败时,测试都会停止。 有没有什么方法可以实际显示循环的结果为六个不同的测试(考虑到我的数据库中有六行)? namespace TestClasses { [TestFixture] public class TestingClass : ConnectionClass { private ProductManagement pm; [TestFixtureSetUp] public void CreateTestClass() { pm = new ProductManagement(); } [TestCase] public void GetProductDetailsTest() { SqlDataAdapter da = new SqlDataAdapter(“Select * From GetProductDetailsTest;”, Connection); Database1DataSet.GetProductDetailsTestDataTable dt = new Database1DataSet.GetProductDetailsTestDataTable(); da.Fill(dt); foreach (Database1DataSet.GetProductDetailsTestRow dr in dt.Rows) { if (pm.GetProductById(dr.productId) == […]

System.BadImageFormatException:尝试使用installutil.exe安装服务时无法加载文件或程序集…格式不正确

我知道我会问重复的问题,但我的情况完全不同我认为是因为当我用我的程序的nunit工具进行unit testing然后在NUnit中发生此错误 “NewTest.testtest(TestFixtureSetUp):SetUp:System.BadImageFormatException:无法加载文件或程序集”AUTO_REPAIR,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null“或其中一个依赖项。尝试加载一个程序格式不正确。“ 我想知道为什么这个工具会发生这个错误? 我确信我在项目或任何测试用例中都没有错误。 请帮帮我。 这是这个错误的图像