Tag: nunit

Selenium – Modal对话框目前 – 如何接受信息?

我有以下问题。 在页面上提交一些日期后,我有一个modal dialog,如图所示: 我想点击“ENTER”来完成该模态,但它不起作用。 我有以下代码: driver.FindElement(By.CssSelector(“input.submit”)).Click(); Actions action = new Actions(driver); action.SendKeys(OpenQA.Selenium.Keys.Enter); 点击继续手动测试后返回下一页。 我必须通过这个模式继续测试。 任何想法如何解决这个问题?

如何使用Visual Studio 2015运行UWP NUnit测试?

这个问题具体是关于运行用C#编写的NUnit通用Windows平台(UWP)unit testing。 如何在Visual Studio中发现并运行这些测试? 我在网上找不到关于此的确切文章,这真的很令人惊讶。

C#Assert.AreNotEqual与Equals

在尝试validation自己时,对于IEnumerables的C#Equals是一个引用等于,我发现了一些奇怪的东西。 在NUnit中进行以下设置 var a = (IEnumerable)(new[] { “one”, “two” }); var b = (IEnumerable)(new[] { “one”, “two” }); 这个测试 Assert.IsFalse(a.Equals(b)); 通过,而这个测试 Assert.AreNotEqual(a, b); 没有。 任何人都可以解释原因吗? 编辑:谢谢你的回答。 我刚刚阅读了NUnit的文档,它说同样的事情,AreEqual和AreNotEqual with collections测试集合中每个元素的相等性。 我想我坚持这个概念,AreEqual和AreNotEqual只是使用普通的Equals。

C#NUnit参数化TestCaseSource值标识

我在NUnit 2.6.1上使用TestCaseSource来测试具有不同对象类构造函数参数的相同Assert。 我的意思是, [Test, TestCaseSource(“myConstructorsForMale”)} public void CheckMale(Person p) { Assert.That(p.IsMale); } static Person[] myConstructorsForMale = { new Person(“John”), new Person(isMale=true), new Person(“Doe”) }; 好的,一切运行正常,但这是我在NUnit控制台上收到的结果: CheckMale CheckMale(人) CheckMale(人) CheckMale(人) 所以我不知道每次迭代执行的测试是什么,如果其中任何一个失败,我就无法得到失败的测试。 我的问题是:有没有办法用注释或类似的东西来识别传递给测试的参数是什么? (在TestCaseSource属性方式中做) 谢谢。

测试自定义AuthorizationAttribute时抛出NullReferenceException

我看了看: 如何进行unit testing以测试检查请求标头的方法? 如何使用moq模拟Controller.User 如何对应用了[Authorize]属性的控制器方法进行unit testing? 我正在尝试测试我编写的自定义AuthorizeAttribute。 我尝试了很多不同的东西来让它发挥作用。 这是我目前的尝试。 [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = true)] public class ConfigurableAuthorizeAttribute : AuthorizeAttribute { private Logger log = new Logger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private IRoleHelper roleHelper; public ConfigurableAuthorizeAttribute() { roleHelper = new ADRoleHelper(); } public ConfigurableAuthorizeAttribute(IRoleHelper roleHelper) { this.roleHelper = roleHelper; } protected override bool AuthorizeCore(HttpContextBase httpContext) { if (!httpContext.User.Identity.IsAuthenticated) […]

c#中的模拟文件IO静态类

我是Unit Testing的新手,我需要在System.IO命名空间中模拟File静态类。 我正在使用Rhinomock,实现这一目标的最佳方法是什么, 让我说我需要模拟File.Exists,File.Delete ……

Nunit测试MVC网站

我试图对我拥有的MVC站点进行unit testing时遇到了一些问题:我需要运行很多ASP.NET环境(生成httpcontexts,会话,cookie,成员资格等)才能完全测试一切。 即使是为了正常工作,也要测试一些较少前端的东西需要会员资格,并且让这一切都被手工欺骗是很挑剔的。 有没有办法在NUnit测试中启动应用程序池? 这似乎是最简单的方法。

如何使用Moq和Autofixture模拟entity framework6

我正在使用AutoMoq,但由于entity framework(使用dbContext和代码优先) dbContext我有点困惑如何编写我的第一个unit testing // in service class(constructor) private readonly MyContext context; public PriceService(MyContext context) { this.context = context; } // following would be in nunit test method. var fixture = new Fixture().Customize(new AutoMoqCustomization()); var priceService = fixture.Create(); 当我运行unit testing时,它会崩溃 在Ploeh.AutoFixture.Kernel.TerminatingSpecimenBuilder.Create(对象请求,ISpecimenContext上下文) 在Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.c__DisplayClass6.b__1(ISpecimenBuilder b) 在System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() 在System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 在System.Linq.Enumerable.d__a5`1.MoveNext() 在System.Linq.Enumerable.FirstOrDefault [TSource](IEnumerable`1 source) 在Ploeh.AutoFixture.Kernel.RecursionGuard.Create(对象请求,ISpecimenContext上下文) 在Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.c__DisplayClass6.b__1(ISpecimenBuilder b) 在System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() 在System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() 在System.Linq.Enumerable.d__a5`1.MoveNext() […]

Moq工作单位

我是unit testing的新手,我想为我的搜索function创建一个测试。 我的服务层看起来像: public class EmployeeService: BaseService, IEmployeeService { public EmployeeService(IUnitOfWork unitOfWork) : base(unitOfWork) { _employeeRepo = unitOfWork.EmployeeRepository; } public IEnumerable Search(Employee advancedSearch, int[] divisionIds, bool showInactive, int pageSize, int? page) { return _employeeRepo.Search(advancedSearch, divisionIds, showInactive, pageSize, page); } } unit testing: [Test] public void SearchShouldFilterActiveEmployees() { var employees = new List { new Employee […]

Nunit测试给出结果OneTimeSetUp:找不到合适的构造函数

我有一个问题,NUnit告诉我:“找不到合适的构造函数”。 是什么导致这个? 我还得到另一条消息:“exception没有堆栈跟踪”。 这两条消息只是一遍又一遍地重复。 这是我的代码 [TestFixture] public class SecurityServiceTests { private IContext stubIContext; private ISecurityService securityService; private IWindsorContainer windsorContainer; public SecurityServiceTests(IContext stubIContext) { this.stubIContext= stubIContext; } [TestFixtureSetUp] public void TestSetup() { //Mocks the database context stubIContext= MockRepository.GenerateStub(); var returnedList = new List(); stubIContext.Stub(a => a.GetUserSecurities(null)).IgnoreArguments().Return(returnedList); securityService = new SecurityService(windsorContainer); } [Test] public void ControllerShouldGetUserGroupForCurrentUsers() { […]