Tag: nunit

多个浏览器使用Webinator + Selenium,SpecFlow和NUnit进行测试

我正在使用Selenium驱动程序使用WebinatorSpecFlow + NUnit开发ASP.NET MVC 3应用程序。 我在使用Chrome(使用chromedriver)和Internet Explorer运行并行测试时遇到问题。 每当我在同一个会话中运行两个测试并通过Webinator并行运行Selenium时,当我向页面发送任何单击操作时,IE似乎都会挂起。 我无法使用此处建议的解决方案,因为SpecFlow会自动生成基础C#代码。 我的解决方案是这样设计的(完整代码可作为要点): _multipleBrowsers.RunTest(web => web.GoToUrl(“http://localhost/PROJECT/Authentication/Registration”)); 会发生什么是我为每个需要测试的浏览器实例化一个新的IWebManager。 然后,我使用浏览器实例调用委托操作。 它是这样的: foreach (var web in _webManagers) { Debug.WriteLine(“Running test with ” + web.Config.Browser); action(web); } 这样,测试几乎并行运行。 它会弹出浏览器,执行操作,然后弹出其他浏览器,等等。 有关如何克服此ChromeDriver问题的任何想法? 我应该使用SpecFlow为多个浏览器更改我的测试方法吗? 参考文献: Webinator specflow NUnit的 ChromeDriver

使用Moq测试抽象类

我正在尝试对抽象类中的方法运行unit testing。 我浓缩了下面的代码: 抽象类: public abstract class TestAb { public void Print() { Console.WriteLine(“method has been called”); } } 测试: [Test] void Test() { var mock = new Mock(); mock.CallBase = true; var ta = mock.Object; ta.Print(); mock.Verify(m => m.Print()); } 信息: Method is not public 我在这做错了什么? 我的目标是使用Moq框架测试抽象类中的方法。

保持您的源关闭和您的unit testing更紧密

当我第一次开始使用unit testing时遇到了两个问题。 首先是能够测试私人方法和领域,然后在快速开发发生时保持unit testing的最新状态。 因此,我采用了以下方法进行unit testing。 #if UNITTEST using NUnit.Framework; #endif public class MyBlackMagic { private int DoMagic() { return 1; } #if UNITTEST [TestFixture] public class MyBlackMagicUnitTest { [TestFixtureSetUp] public void Init() { log4net.Config.BasicConfigurator.Configure(); } [Test] public void DoMagicTest() { Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); Assert.IsTrue(DoMagic() == 1, “You are not a real magician!”); } } #endif } […]

适用于C#NUnit的BDD

我一直在使用家庭酿造的BDD Spec扩展来在NUnit中编写BDD样式测试,我想看看每个人都在想什么。 它增加了价值吗? 真是太糟糕了? 如果是这样的话? 那里有更好的东西吗? 这是源: https : //github.com/mjezzi/NSpec 我创建这个有两个原因 使我的测试易于阅读。 产生简单的英语输出以查看规格。 以下是测试外观的示例: – 这些天僵尸似乎很受欢迎.. 鉴于Zombie,Peson和IWeapon: namespace Project.Tests.PersonVsZombie { public class Zombie { } public interface IWeapon { void UseAgainst( Zombie zombie ); } public class Person { private IWeapon _weapon; public bool IsStillAlive { get; set; } public Person( IWeapon weapon ) { […]

unit testing具有事件和委托的类

我是新手测试请帮助。 我有以下课程 public delegate void OnInvalidEntryMethod(ITnEntry entry, string message); public class EntryValidator { public event OnInvalidEntryMethod OnInvalidEntry; public bool IsValidEntry(ITnEntry entry, string ticker) { if (!IsFieldValid(entry, ticker.Trim().Length.ToString(), “0”)) return false; return true; } private bool IsFieldValid(ITnEntry entry, string actual, string invalidValue) { if (actual == invalidValue) { RaiseInvalidEntryEvent(entry); return false; } return true; } private […]

Nunit ExpectedException正常工作吗?

在设置一些命令行脚本来测试我正在处理的项目的NUnit测试套件时,我开始遇到问题。 我注意到在Visual Studio或Xamarin中运行测试时结果是我的预期,但是当使用nunit-console (mac v2.4.8 )从命令行运行时,它不会使某些测试失败。 在控制台中失败的所有失败的测试都使用[ExpectedException]属性(两者都有类型和一般)。 更改为使用Assert.Throws它在IDE和命令行中都能正常工作。 这是Nunit或我拥有的特定版本/平台的错误吗?

是否有用于指定配置的NUnit测试用例属性

我正在编写一个NUnit测试,我想只在Release配置中运行。 使用测试用例属性是否有一种优雅的方式? 现在,我用编译器指令围绕整个function块: 我正在使用Nunit 2.5.6.10205。 #if !DEBUG [Test] public void MyReleaseOnlyTest() { // stuff } #endif

Selenium c#接受确认框

我在c#中使用selenium编写了一个nUnit测试。 一切顺利,直到我必须确认一个JS确认框。 这是我正在使用的代码: this.driver.FindElement(By.Id(“submitButton”)).Click(); this.driver.SwitchTo().Alert().Accept(); 提交按钮后出现确认框。 确认出现然后立即消失,但表单不提交。 无论上面的accept()行如何,行为都是相同的。 我使用的是Firefox v15.0.1和selenium v​​2.24 我尝试在提交点击和确认接受之间放置一个Thread.Sleep。 我读过的所有内容都说selenium驱动程序会自动发送确认信息,但其他内容似乎正在发生。

Nunit-C#:通过编码运行特定的测试

我正在使用Selenium和C#进行自动化,我想通过代码调用NUnit,如下所示: CoreExtensions.Host.InitializeService(); TestPackage testPackage = new TestPackage(@”D:\Automation\bin\Debug\Test.dll”); RemoteTestRunner remoteTestRunner = new RemoteTestRunner(); remoteTestRunner.Load(testPackage); //TestFilter filter = new NameFilter(new TestName() { Name = “Test1” }); TestResult testResult = remoteTestRunner.Run( new NullListener(), TestFilter.Empty, false, LoggingThreshold.Off ); 我可以使用类别filter运行测试,如下所示 remoteTestRunner.Run( new NullListener(), new CategoryFilter(“MyCat”), false, LoggingThreshold.Off ); 但我想执行特定的测试。 如何设置套件filter? 我尝试了以下,但它不起作用: TestFilter filter = new NameFilter(new TestName() { Name = […]

指定要运行的NUnit测试

我有一个NUnit项目,用于创建用于运行测试的控制台应用程序。 入口点如下所示: class Program { [STAThread] static void Main(string[] args) { string[] my_args = { Assembly.GetExecutingAssembly().Location }; int returnCode = NUnit.ConsoleRunner.Runner.Main(my_args); if (returnCode != 0) Console.Beep(); } } 如果我只想运行这个测试,我可以作为参数传递什么: [TestFixture] public class EmailNotificationTest { [Test] public void MailerDefaultTest() { Assert.IsTrue(false); } } 显然这是支持的,同样清楚我不知道如何做到这一点。 UPDATE 看起来像v3 +, 根据文档可以使用–test选项。