简体   繁体   English

如何通过 windows 应用程序调用单元测试项目?

[英]how to call a unit test project by a windows application?

I am new to selenium and C sharp i somehow managed to write a code that does the unit testing of my application and creates a Extent Report with all my 7 test cases output Everything is working as expected The issue is i do not want every time to log into visual studio and run the selected test case Is there any way i can create a Windows application and make the test cases run with a click of a button我对 selenium 和 C 很陌生登录到 Visual Studio 并运行选定的测试用例有什么方法可以创建 Windows 应用程序并通过单击按钮运行测试用例

I have a total of 7 test cases and runs perfectly when running i select them all and run the selected tests, but i need not want to go there everytime, instead want to run it from some windows application.我总共有 7 个测试用例,并且在运行我 select 并运行选定的测试时完美运行,但我不需要每次都在那里 go ,而是想从一些 Z0F4137ED1502B5045D2Z608A6A 应用程序运行它。

If you have your tests in unit tests project, you can create a windows console app and add your test project as dependency to it.如果您在单元测试项目中有您的测试,您可以创建一个 windows 控制台应用程序并将您的测试项目添加为它的依赖项。

Then you can create your test class objects in main function and call test methods.然后您可以在主 function 中创建您的测试 class 对象并调用测试方法。

using Test.Project.Namespace;

    static void Main(string[] args)
            {
                TestClass testclass = new TestClass();
                testclass.TestMethod1();
                testclass.TestMethod2();
                etc...
            }

It can be improved in many ways but you got the idea.它可以在很多方面进行改进,但你明白了。

I would suggest that you create a Windows batch file that triggers your automation.我建议您创建一个触发自动化的 Windows 批处理文件。 Since you are using NUnit, this should be pretty straightforward.由于您使用的是 NUnit,这应该非常简单。 You point it at your automation dlls, you can specify test categories, etc. Take a look at the docs and other resources on the web.您将其指向您的自动化 dll,您可以指定测试类别等。查看 web 上的文档和其他资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM