如何在Nunit项目中进行测试

编程入门 行业动态 更新时间:2024-10-15 02:28:22
本文介绍了如何在Nunit项目中进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个方法:

Hi , I have this method :

public static IEnumerable<W_H59MpxSessionFrais> ListeSessionFrais(MpxFraisContext db, int siteID, int stval, string codeFrais) { var sessionfrais = (from D1 in db.H59_MpxSessionFrais where D1.CodeFrais == codeFrais && D1.SiteId == siteID && D1.StatusValidation == stval select new W_H59MpxSessionFrais { ID = D1.SessionFraisId, LibelleSession = D1.LibelleSession, DateDebutSession = D1.DateDebutSession, DateFinSession = D1.DateFinSession }); return sessionfrais.ToList(); }

我想和Nunit一起测试,但我不知道如何在类测试中将值填充到MpxFraisContext,如果有人有想法请告诉我如何做测试类知道我正在使用asp MVC 4,Razor和linq到实体

and i want to do test with Nunit but i don't know how to fill values to MpxFraisContext in the class test , if someone have an idea please tell me how to do the test class knowing that i'm working with asp MVC 4 ,Razor and linq to entities

推荐答案

您可以使用数据库数据和模拟数据编写Unittest。如果你想创建一个模拟层,我建议你实现存储库模式和依赖注入。 下面的例子我用基本的ASP.NET演示了一个基本的单元测试不使用依赖注入的MVC Unitesting框架 You can write Unittest with both database data and Mock data. If you want to create a mock layer i recommend you implement the Repository Pattern and Dependency Injection. The below example i have demonstrate a basic unit test with basic ASP.NET MVC Unitesting framework without using Dependency Injection [TestClass] public class YourControllerTest { private readonly SettingsController _settingsController = null; public SettingsControllerTest() { _settingsController=new SettingsController(); } [TestMethod] public void ListeSessionFraisType_Of_IEnumerable_W_H59MpxSessionFrais() { var indexModel = _settingsController.ListeSessionFrais(); Assert.IsInstanceOfType(indexModel, typeof(IEnumerable<W_H59MpxSessionFrais>)); } }

不要将datacontext作为参数传递。请遵循存储库模式。它还将从代码中抽象出datacontext,并且可以单独测试业务逻辑(存储库)。你将从网上获得很多代码示例来获取存储库模式 希望这有帮助

Don't pass datacontext as a parameter. Please follow the Repository pattern.It will also abstract the datacontext away from the code and can test the business logic(Repositories) alone. You will get a lot code examples from the net for Repository Pattern Hope this helps

我正在使用Nunit而不是MS测试我想要测试此方法的类 i'm working with Nunit not MS test and i want to have test class for this method

更多推荐

如何在Nunit项目中进行测试

本文发布于:2023-11-06 23:58:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进行测试   项目   如何在   Nunit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!