UnitTest 项目的代码与源代码同步吗?

发布于 2024-12-16 16:12:42 字数 403 浏览 4 评论 0原文

我有一个名为 - UnitTestProject 的 Visual Studio 解决方案,使用 xunit 框架进行单元测试。

在此解决方案下,一个名为 - MainProject 和 MainProject_Test 的项目,

MainProject 是实现的“真实”源,MainProject_Test 用于单元测试,其中包含 xunit 属性、Assert 等。

我的问题是,每次我对 MainProject 进行更改时,我都会必须复制并粘贴到 MainProject_Test,这不是有效的方法。

那么人们如何反映代码但保留属性或断言呢?

另一个问题是,UnitTest项目有命名约定吗? MainProject_Test / MainProject.Test 还是 MainProjectTest?

I have a Visual Studio solution named - UnitTestProject, unit test with xunit framework.

Under this solution, a project named - MainProject and MainProject_Test,

The MainProject is the "Real" Source for implementation, the MainProject_Test for unittest, which contain the xunit attribute,Assert etc..

My question is, everytime i make change on MainProject, i have to copy&paste to MainProject_Test, it is not efficient way.

So how did the people reflect the code but retain the attribute or Assertion ?

Another question is, is it any name convention of UnitTest project? MainProject_Test / MainProject.Test or MainProjectTest?

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

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

发布评论

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

评论(2

无声无音无过去 2024-12-23 16:12:42

您应该从单元测试项目中引用您的主项目。在解决方案资源管理器中右键单击测试项目的引用节点以添加引用。

我将测试项目命名为 MainProject.Test

You should reference your main project from your unit test project. Right-click on the references node of the test project in solution explorer to add the reference.

I would name the test project MainProject.Test.

迷鸟归林 2024-12-23 16:12:42

MainProject_Test 应引用 MainProject。它不应该拥有所有代码的副本。

常见的命名约定是 MainProject 和 MainProject.Tests,但这样的约定有很多。

MainProject_Test should reference MainProject. It shouldn't have a copy of all its code.

A common naming convention is MainProject and MainProject.Tests, but there are a number of such conventions.

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