如何测试辅助方法?
我已经制作了一个助手,
public static class UrlHelperExtension
{
public static string GetContent(this UrlHelper url, string link, bool breakCache = true)
{
// stuff
}
}
如何在单元测试中测试它?
[TestClass]
public class HelperTestSet
{
[TestMethod]
public void GetContentUrl()
{
// What do I need to do here?
// I need a RequestContext to create a new UrlHelper
// Which is the simplest way to test it?
}
}
如何创建测试所需的助手?
I've made a helper
public static class UrlHelperExtension
{
public static string GetContent(this UrlHelper url, string link, bool breakCache = true)
{
// stuff
}
}
How do I test it in a unit test?
[TestClass]
public class HelperTestSet
{
[TestMethod]
public void GetContentUrl()
{
// What do I need to do here?
// I need a RequestContext to create a new UrlHelper
// Which is the simplest way to test it?
}
}
How do I create the helper needed for the test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你真的想完全解耦地测试它,你必须引入另一层抽象。所以在你的情况下你可以这样做:
If you really want to test it totally uncoupled, you have to introduce another layer of abstraction. So in your case you could do something like this:
阅读以下网址可能会对您有所帮助。
测试扩展方法
Read the following URl may help you.
test the extension methods
从这个网站我想出了
From this website I came up with