简体   繁体   中英

Run coded ui test from WPF application (without using mstest)

I want to run my coded ui test cases from a WPF application. However, when I initialize playback and call the test method, I am getting an error that the TestContext is NULL. Could anyone pls suggest if execution of coded ui test via WPF application is possible? Also, how can I access the TestContext in this approach as the test cases are data driven and I need to access TestContext.

Thanks.

This a behavior question of test runners

TestConext is populated at run time of the "TestHarness/TestRunner". Its is an abstract class that in Visual Studio the process is called QAagent32.exe that supplies an implemented version for this based upon what your test method and class requires of it, eg Iterating data rows from a Excel Worksheet , TFS TestCase parameter data table; Coded UI, Unit Test. If you want to use what is already used in Visual Studio you can just call GetType() on it, and research from there for its fully qualified type used. However, IF that class type isn't available you'll have to implement a concrete class that fully implements TestContex

Then in code you can do like the following:

PlayBack.Initialize();
var yourTestClass = new YourUniqueClassTests();
yourTestClass.TestContext = TestConextFactory.GetImplimentation();
yourTestClass.TestMethodThatsImportant();

Now if your using the DataSource attribute on your test methods you will probably have to use reflection to pull that info.

var attribute= yourTestClass.GetType()
                            .GetMethod("TestMethodThatsImportant")
                            .GetCustomAttributes(typeof(DataSourceAttribute),false)[0] 
                             as DataSourceAttribute;

This should be able to get that data for you. Once you have it you could add logic to decide on what type of TestContext object you implement to set on the test class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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