如何找到包含NUnit的测试dll文件 [英] How to find dll files containing nunit tests

查看:176
本文介绍了如何找到包含NUnit的测试dll文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多的dll的文件夹。其中一个包含NUnit的测试中(标有[测试]属性功能)。我想运行在C#code NUnit测试。有没有办法找到合适的dll?

I have a folder with many dlls. One of them contains nunit tests (functions marked with [Test] attribute). I want to run nunit test from c# code. Is there any way to locate the right dll?

谢谢

推荐答案

您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.loadfile.aspx">Assembly.LoadFile方法来加载DLL到一个Assembly对象。然后使用<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.gettypes.aspx">Assembly.GetTypes方法来获取所有的组件定义的类型。然后使用 GetCustomAttributes 的方法,你可以检查,如果该类型的装饰用[的TestFixture]属性。如果你想让它快'东经肮脏的,你可以只调用.GetType()。toString()方法对每个属性,并检查是否字符串包含TestFixtureAttribute。

You can use Assembly.LoadFile method to load a DLL into an Assembly object. Then use the Assembly.GetTypes method to get all the types defined in the assembly. Then using the GetCustomAttributes method you can check if the type is decorated with the [TestFixture] attribute. If you want it quick 'n dirty, you could just call .GetType().ToString() on each attribute and check if the string contains "TestFixtureAttribute".

您还可以检查里面的每一种方法。使用方法 Type.GetMethods 来检索它们,并使用GetCustomAttributes对他们每个人的,这时候搜索TestAttribute。

You can also check for the methods inside each type. Use the method Type.GetMethods to retrieve them, and use GetCustomAttributes on each of them, this time searching for "TestAttribute".

这篇关于如何找到包含NUnit的测试dll文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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