在c#中测试应用程序 [英] Test Application in c#

查看:92
本文介绍了在c#中测试应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!!!



我有一个包含25个项目的解决方案的源代码!!因此,它同时具有C#和托管c ++代码。我需要测试一个C#项目调用。但是这个项目的类型是Window application(不是DLL)。即使它是Windows应用程序,我的要求是只调用几个内部函数调用(与Windows窗体无关)。现在我需要创建一个单独的C#测试项目来调用这些功能。有可能这样做吗?任何人都可以建议一种方式或例子吗?还有一件事,我没有任何修改现有源代码的自由。



提前谢谢。

Hello!!!

I am having a source code with a solution having 25 projects!!. So, it is having both C# and managed c++ code also. i need to test one of the C# project calls. but this project is of type "Window application"(Not DLL). Even though it is windows application, my requirement is to call only few internal functional calls (Not related to windows form). Now i need to create a separate C# test project to call these functionality. is it possible to do it like this? can any one suggest a way or examples? And one more thing, i don't have any freedom to modify the existing source code.

Thanks in advance.

推荐答案

看起来您的目标是为您的解决方案开发单元测试,这是一件好事。它可以通过许多不同的方式完成。

首先,请阅读: http:// en。 wikipedia.org/wiki/Unit_testing [ ^ ]。



首先,您可以创建和添加一些测试项目。尽管有通用单元测试技术不需要创建任何特定于应用程序的测试项目(请参见下文),但其他类型的测试和整个开发策略可能需要它们,所以我会给你一些想法。此外,有一些原型项目是个好主意。



所以,看起来测试一些EXE似乎对你来说是一个问题。在这里,您应该理解一件简单的事情:您可以引用EXE(或任何类型的程序集),就像DLL一样。从本质上讲,对于.NET,没有EXE和DLL,只有汇编。某些测试项目程序集可以引用任何这些程序集。现在,一个小问题是:如果你在内部使用某些类型/成员进行程序集,你应该给它们 internal 访问说明符,但是在引用程序集中使用它们公共。那说:1)您可以在测试中的程序集内部创建特殊测试并将它们公开,可能是有条件的(取决于 #define 预处理器条件),或者2)你可以在测试项目中使用Reflection,因为无论访问说明符如何,Reflection都可以工作。由于反射方法比较困难,您可以考虑使用一些现有的单元测试设备。



对于第三方测试设施,我建议开源 NUnit:

http://en.wikipedia.org/wiki/NUnit [ ^ ],

http://www.nunit.org/ [ ^ ]。



由于您只测试.NET项目,因此大大简化了您的问题。 C ++ / CLI和C#项目实际上它们之间没有任何障碍。你可以考虑其他设施。请参阅此列表:

http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks# .NET_programming_languages [ ^ ]。



基本上,您只创建可以用特殊属性标记的测试。该实用程序找到测试并自动执行测试。您有责任提供相当全面的测试装置。不要忘记:测试永远不会保证软件的正确性。



-SA
It looks like you are aiming to develop unit testing for your solution(s), which is a good thing. It can be done in many different ways.
First of all, please read: http://en.wikipedia.org/wiki/Unit_testing[^].

First of all, you can create and add some test projects. Even though there are universal unit testing techniques which don't require creation of any application-specific test projects (please see below), other types of testing and the whole development strategy may require them, so I'll give you some idea. Besides, it's a good idea to have some prototype projects.

So, it looks like testing some EXE seems to be a problem for you. Here, you should understand one simple thing: you can reference EXE (or any kinds of assemblies for that matter), exactly as DLLs. Essentially, for .NET, there are no EXEs and DLLs, there are just assembly. Any of those assemblies can be referenced by some test-project assembly. Now, a little problem is: if you use some types/members internally for the assembly, you should give them internal access specifiers, but using them from a referencing assembly required public. That said: 1) you can create special tests inside the assembly under the test and make them public, probably conditionally (depending on #define preprocessor conditions), or 2) you can use Reflection in your test projects, as Reflection can work regardless of access specifiers. As Reflection approach is more difficult, you may consider using some existing unit testing facility.

For a 3rd-party testing facility, I would recommend open-source NUnit:
http://en.wikipedia.org/wiki/NUnit[^],
http://www.nunit.org/[^].

Your problem is greatly simplified by the fact that you only test .NET project. C++/CLI and C# project practically don't have any barriers between them. You can consider other facilities. Please see this list:
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#.NET_programming_languages[^].

Basically, you create only the tests, which can be marked by special attributes. The utility finds the tests and perform testing automatically. It's your responsibility to provide a test set which is fairly comprehensive. And don't forget: testing along will never guarantee the correctness of your software.

—SA


这篇关于在c#中测试应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆