如何用Nunit进行测试

编程入门 行业动态 更新时间:2024-10-17 09:46:05
本文介绍了如何用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一起测试,如果有人有想法请告诉我怎么做测试课知道我正在使用asp MVC 4,Razor和linq到实体

and i want to do test with Nunit ,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

推荐答案

你到底在哪里? 可能与 MpxFraisContext db 参数。在这里你需要一个模拟。也就是说,该类型的对象包含一些数据或没有(取决于单数测试)。您可以自己创建这样的对象,或使用模拟框架,例如Moq。 函数可能如下所示: Where exactly are you stuck? Possibly with the MpxFraisContext db parameter. Here you need a "mock". That is, an object of that type which contains some data or none (depending on the singular test). You may create such an object yourself, or use a "mocking framework", e.g. Moq. A function could look like: [Test] public void TestListeSessionFrais() { MpxFraisContext db = [create and fill that object with useful data] int siteID = 1; int stval = 2; string codeFrais = "a"; IEnumerable<w_h59mpxsessionfrais> retVal = [YourClass].ListeSessionFrais(db, siteID, stval, codeFrais); int expectedCount = 1; Assert.IsNotNull(retVal, "the function must return a value different from null"); //... some more Asserts on the returned object, e.g. count, properties of first object in list,... }</w_h59mpxsessionfrais>

如何在测试类中使用mock? how to use mock in test class ?

更多推荐

如何用Nunit进行测试

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

发布评论

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

>www.elefans.com

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