How to test a WPF user interface?

前端 未结 9 546
余生分开走
余生分开走 2020-12-04 07:46

Using win forms with an MVC/MVP architecture, I would normally use a class to wrap a view to test the UI while using mocks for the model and controller/presenter. The wrapp

9条回答
  •  一向
    一向 (楼主)
    2020-12-04 08:41

    2016 Update: Use the free TestStack.White framework to automate WPF UI testing

    • Project White has been abandoned, but its successor TestStack.White is available via a NuGet package.
    • TestStack.White has utility methods for starting WPF apps, finding window/user control elements, clicking buttons/elements, simulating mouse and keyboard events, waiting, etc..
    • An example that will launch a WPF app, click a button, and check for result looks like the following:

      using TestStack.White;
      using TestStack.White.UIItems;
      using TestStack.White.Factory;
      
      [TestMethod]
      public void TestDoSomething()
      {
          //Opens the app
          var app = Application.Launch("MyApp.exe");
      
          //Finds the main window (this and above line should be in [TestInitialize])
          var window = app.GetWindow("My App Window Title", InitializeOption.NoCache);
      
          //Finds the button (see other Get...() methods for options)
          var btnMyButton = window.Get

提交回复
热议问题