1 / 24

Module 5 Testing, Unit Testing, and Debugging

Module 5 Testing, Unit Testing, and Debugging. Module Overview. WPF Testing Strategies Debugging XAML Providing User Feedback for Unhandled Exceptions Understanding Security Features. Lesson 1: WPF Testing Strategies. Understanding How to Test Windows Client Applications

dennis
Download Presentation

Module 5 Testing, Unit Testing, and Debugging

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Module 5 Testing, Unit Testing, and Debugging

  2. Module Overview • WPF Testing Strategies • Debugging XAML • Providing User Feedback for Unhandled Exceptions • Understanding Security Features

  3. Lesson 1: WPF Testing Strategies • Understanding How to Test Windows Client Applications • Strategies for Testing Windows Client Applications • Testing by Using Unit Tests in Visual Studio • Understanding UI Automation • Testing by Using UI Automation

  4. Understanding How to Test Windows Client Applications Why test? • Reduce the cost of development • Ensure that your application behaves predictably • Reduce the total cost of ownership Types of Testing: • Unit testing • Integration testing • Regression testing

  5. Strategies for Testing Windows Client Applications Unit testing • Good for testing business logic • Make unit testing easier by using design patterns: • MVP • MVVM • IoC • DI UI Automation • Good for interactive testing • Simulates using input devices, such as: • Keyboard • Mouse

  6. Testing by Using Unit Tests in Visual Studio Different types of tests: • Unit test • Coded UI test • Database unit test using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CustomerUnitTests { [TestMethod] public void MyUnitTest() { // Add your test logic here. } }

  7. Understanding UI Automation Control patterns: • ExpandCollapse control pattern • Invoke control pattern • Toggle control pattern • Grid control pattern • RangeValue control pattern • Window control pattern • More… UI Automation core concepts: • Providers • Clients

  8. Testing by Using UI Automation Steps to invoke a control: Create an AutomationElement instance 1 Obtain the pattern object 2 Use the methods that the pattern provides 3 // Create an Automation instance from Button1. AutomationElement button = AutomationElement.RootElement.FindFirst( TreeScope.Descendants, new PropertyCondition( AutomationElement.AutomationIdProperty, "Button1")); // Obtain the pattern object. InvokePattern pattern = (InvokePattern) button.GetCurrentPattern(InvokePattern.Pattern); // Click the Button by using the pattern. pattern.Invoke();

  9. Lesson 2: Debugging XAML • Understanding Debugging in Visual Studio • Demonstration: Debugging XAML by Using Visual Studio • Debugging by Using Tracing

  10. Understanding Debugging in Visual Studio Visual Studio debugging capabilities: • Setting break points in your code • Inspecting memory and register values • Viewing and changing variables values • Observing message traffic New Visual Studio debugging features: • WPF Tree Visualizer • Tracing by using PresentationTraceSources

  11. Demonstration: Debugging XAML by UsingVisual Studio In this demonstration, you will see how to: • Open the WPF Tree Visualizer • Explore the visual tree • Search for properties on an element

  12. Debugging by Using Tracing PresentationTraceSources.TraceLevel can be applied to: • Classes that are derived from BindingBase • BindingExpressionBase and its derived classes • Classes that are derived from DataSourceProvider Different trace levels: • None • Low • Medium • High

  13. Lesson 3: Providing User Feedback forUnhandled Exceptions • Understanding Unhandled Exceptions • Processing Unhandled Exceptions

  14. Understanding Unhandled Exceptions What are unhandled exceptions? • Exceptions are a standard mechanism for reporting errors • An exception that you do not handle in your code is an unhandled exception Only catch exceptions you can handle and recover from Why process unhandled exceptions? • Error logging and reporting • Improve user experience by presenting errors to your users consistently

  15. Processing Unhandled Exceptions Adding a handler for unhandled exceptions for WPF applications this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler( OnDispatcherUnhandledException); Adding a handler for unhandled exceptions for non-WPF applications AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler( OnUnhandledException);

  16. Lesson 4: Understanding Security Features • Understanding Security in Windows Client Applications • Understanding Code Access Security • Understanding Full Trust and Partial Trust in WPF • Understanding User Access Controls

  17. Understanding Security in Windows Client Applications Available security technologies and aspects: • SRP • CAS • Partial trust and full trust in WPF • UAC In the .NET Framework version 4, the CLR is moving away from providing security policy for computers Microsoft is recommending the use of Windows Software Restriction Policies as a replacement for CLR security policy

  18. Understanding Code Access Security Code Access Security: • Protects you from malicious code • Enables code to be trusted to varying degrees • Enforces varying levels of trust • Reduces the likelihood that malicious code can misuse your code Major changes have been made to CAS in the .NET Framework version 4 The most notable change has been security transparency, but there are also other significant changes that affect CAS

  19. Understanding Full Trust and Partial Trust in WPF Available in partial trust: Not available in partial trust: • Browser window • Site-of-origin access • Isolated storage (512 KB limit) • UI Automation providers • Commanding • IMEs • Tablet stylus and ink • Simulated drag and drop • Many more… • Window (application-defined windows and dialog boxes) • SaveFileDialog • File system • Registry access • Drag-and-drop • XAML serialization (via XamlWriter.Save) • UIAutomation clients • Many more…

  20. Understanding User Access Controls User Account Control has the following benefits: • It reduces the number of programs that run with elevated privileges • It enables you to be productive when you run as a Standard user by removing unnecessary restrictions • It gives you the ability to ask an administrator to give you permission to perform an administrative task in their current session

  21. Lab: Testing and Debugging WPF Applications • Exercise 1: Unit Testing Strategy • Exercise 2: Unit Testing in WPF Applications • Exercise 3: Debugging Applications in Visual Studio 2010 • Exercise 4: Advanced Exception Handling Logon information Estimated time: 75 minutes

  22. Lab Scenario You have been asked to create unit tests for the UI code that you have written so far. First, you must decide on the best approach to use to test each class, and then you must write the necessary code. During testing, you discover that you have a couple of hard-to-find bugs, and you must use the tooling support that Visual Studio 2010 provides to track down and resolve these bugs.

  23. Lab Review Review Questions • What is the most appropriate strategy for testing UI elements? • What is the name of the new debugging visualizer in Visual Studio 2010 for inspecting WPF elements? • What is the name of the event on the Application class for processing unhandled exceptions?

  24. Module Review and Takeaways • Review Questions • Best Practices • Tools

More Related