在旧网站上实施单元测试

发布于 2024-07-25 23:22:13 字数 383 浏览 1 评论 0原文

我下载了 nUnit 和 TestDriven.net。 我有一个旧的网站应用程序,我想实现一些单元测试。 我在 app_code 文件夹中创建了一个类,并添加了 Imports NUnit.Framework 等...编写基本测试后,我得到“无法在‘网站’应用程序中执行测试”。 错误。 我猜网站项目不受支持。 目前无法选择转换为 Web 应用程序。 我有 Visual Studio 测试版,所以我尝试了这条路线。 我创建了一个测试项目,在我的测试类中编写了几个测试等...却发现我无法引用网站项目的 app_code 文件夹中的类。 有人可以给我一些指点吗??? 难道我做错了什么。 我对 TDD 还很陌生。 我只想对此应用程序正确实施一些测试。

提前致谢, 〜ck在圣地亚哥

I downloaded nUnit and TestDriven.net. I have a legacy Web Site application and I would like to implement some unit testing. I created a class in the app_code folder and added Imports NUnit.Framework etc... After writing a basic test, I get the "Can't execute tests in 'Web Site' application." error. I guess the Web Site project is not supported. Converting to a Web Application is not an option at this time. I have Visual Studio Test Edition, so I tried that route. I created a test project, wrote a couple tests in my test class etc... only to find out I cannot reference the classes in the app_code folder of the Web Site project. Can anyone out there give me some pointers??? Am I doing something wrong. I am pretty new to TDD. I just want to properly implement a bit of testing on this application.

Thanks In Advance,
~ck in San Diego

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坚持沉默 2024-08-01 23:22:13

为单元测试创​​建一个单独的项目,尤其是在您使用网站时。

您可能不应该对网站中的类进行单元测试。 相反,您想要进行单元测试的任何类可能都不应该出现在网站中。 相反,它们应该位于网站引用的类库项目中。

这是不使用网站的另一个原因:它们在使用之前不会编译,因此 app_code 中没有代码的编译版本供您的测试项目进行测试。

网站只能用于简单的网站。 其他任何事情都比他们想要处理的更复杂。 请改用 Web 应用程序项目(但仍将必须有趣的代码保留在项目之外)。

Create a separate project for unit tests, especially if you are using a web site.

You should probably not be unit testing the classes in your web site. Rather, any classes you'd want to unit test, should probably not be in the web site. Rather, they should be in a class library project that is referenced by the web site.

This is yet another reason to not use web sites: they do not compile until they are used, so there is no compiled version of the code in app_code for your test project to test.

Web sites should be used for nothing other than simple web sites. Anything else is more sophisticated than they were intended to handle. Use a Web Application Project instead (but still keep must interesting code out of the project).

心头的小情儿 2024-08-01 23:22:13

我认为约翰·桑德斯的建议很中肯。 您想要尝试将该网站作为表示层,并将组成业务逻辑的类隔离到一个单独的库中以进行测试。 这使您可以只关注这些类要实现的过程。

所以你知道我开始使用 nUnit 进行 TDD,然后在一个主要项目中使用 MS 测试套件。 我会选择 nUnit 而不是 MS,因为它更快。

I think John Saunders has sound advice. You want to try the web site a presentation layer and isolate the classes that comprise the business logic into a separate library for testing. This allows you to focus solely on the processes that the classes are intended to implement.

So you know I started out TDD with nUnit then used the MS Test suite for a major project. I would chose nUnit over MS as it was much faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文