0
Tool Development
Chapter 09: Localization & Testing
Nick Prühs
July 2, 2014
5 Minute Review Session
• Which wildcards are available at the windows
command prompt?
• How do you access parameters in b...
Assignment Solution #8
DEMO
3 / 58
Objectives
• To understand how to globalize and localize WPF
applications
• To learn how to properly set up automatic test...
Globalization & Localization
• When you limit your product's availability to only
one language, you limit your potential c...
Globalization & Localization
• Globalization is the design and development of
applications that perform in multiple locati...
WPF UI Design Best Practice
• Write your UI in XAML; avoid creating UI in code.
• Avoid using absolute positions and fixed...
Localizing WPF Applications
1. Add a Uid property by running msbuild /t:updateuid
ProjectName.csproj in a developer comman...
LocBaml CSV Fields
• BAML Name. The name of the BAML resource with
respect to the source language satellite assembly.
• Re...
Gotcha!
Both the LocBaml tool and your
application must target the same
platform and .NET framework!
10 / 78
Gotcha!
The locale specified for the LocBaml
tool and the localization folder
must match!
11 / 78
Localizing the Level Editor
DEMO
12 / 58
“How do you automate a client-server, distributed,
persistent, sharded, asynchronous, realtime, scalable
system?”
13 / 58
“How do you automate a client-server, distributed,
persistent, sharded, asynchronous, realtime, scalable
system?”
“Very ca...
Unit Testing
• Method by which individual units of source code
are tested to determine if they are fit for use
• Unit of s...
Unit Testing
• Ideally, each test case is independent from the
others
• Substitutes such as mocks can be used to assist
te...
Advantages of Unit Testing
 Finds problems early
• Test Driven Development
 Facilitates changes
• Can be run before each...
Limits of Unit Testing
• Won’t catch every error in the program
• Won’t catch integration errors
• Combinatorial problem
•...
Limits of Unit Testing
• Setting up realistic and useful tests is a challenge
• Test case failures need to be reviewed dai...
Unit Testing with NUnit
• Unit Testing framework for all .NET languages
• Initially ported from JUnit
• Written entirely i...
Setting up NUnit
1. Add new Class Library project to the solution.
2. Add reference to
bin/framework/nunit.framework.dll.
...
NUnit Test Class Design
• Public
• Default constructor
22 / 58
NUnit Test Method Design
• [Test] attribute
• Return void
• No parameters
23 / 58
NUnit Test Example
C#
24 / 58
namespace LevelEditor.Tests
{
using LevelEditor.Model;
using NUnit.Framework;
public class M...
NUnit Assertions
• AreEqual, AreNotEqual
• AreSame, AreNotSame
• IsTrue, IsFalse
• Greater, GreaterOrEqual
• Less, LessOrE...
Expected Exceptions
C#
26 / 58
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestNegativeWid...
SetUp and TearDown
C#
27 / 58
public class MapTest
{
private const int Height = 16;
private const int Width = 32;
private ...
Hint
Override Equals in types whose
objects you need to compare!
28 / 78
NUnit Test Tool
29 / 78
NUnit Console
Console Output
30 / 58
D:DevRepositoriesSAE-ToolDevelopmentVendorNUnit-2.6.3bin>nunit-console-x86.exe
.........
NUnit & Visual Studio
31 / 78
NUnit & Visual Studio
32 / 78
Test Driven Development
1. Write an (initially failing) automated test
case that defines a desired improvement or new
func...
Advantages of TDD
 Client-first development
 Taking small steps
 All written code is covered by at least one test
 Can...
Limits of TDD
• Support of the entire team is essential
• Test are typically created by the developer who is
writing the c...
Assignment #9
Unit Tests
1. Download NUnit from
http://nunit.org/index.php?p=download and add it to
your project.
2. Write...
References
• MSDN. WPF Globalization and Localization Overview.
http://msdn.microsoft.com/en-
us/library/ms788718(v=vs.110...
Thank you for your attention!
Contact
Mail
dev@npruehs.de
Blog
http://www.npruehs.de
Twitter
@npruehs
Github
https://githu...
Upcoming SlideShare
Loading in...5
×

Tool Development 09 - Localization & Testing

796

Published on

Chapter 09 of the lecture Tool Development taught at SAE Institute Hamburg.

Introduction to globalization and localization of WPF applications, as well as unit testing with NUnit.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
796
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Tool Development 09 - Localization & Testing"

  1. 1. Tool Development Chapter 09: Localization & Testing Nick Prühs July 2, 2014
  2. 2. 5 Minute Review Session • Which wildcards are available at the windows command prompt? • How do you access parameters in batch files? • Which redirection operator writes the command output to a file or a device instead of the Command Prompt window? • How do you access command-line parameters in .NET? • How do start other programs from your .NET application? 2 / 58
  3. 3. Assignment Solution #8 DEMO 3 / 58
  4. 4. Objectives • To understand how to globalize and localize WPF applications • To learn how to properly set up automatic testing for your WPF applications 4 / 58
  5. 5. Globalization & Localization • When you limit your product's availability to only one language, you limit your potential customer base to a fraction of our world’s 6.5 billion population. • If you want your applications to reach a global audience, cost-effective localization of your product is one of the best and most economical ways to reach more customers. 5 / 58
  6. 6. Globalization & Localization • Globalization is the design and development of applications that perform in multiple locations. For example, globalization supports localized user interfaces and regional data for users in different cultures. • Localization is the translation of application resources into localized versions for the specific cultures that the application supports. 6 / 58
  7. 7. WPF UI Design Best Practice • Write your UI in XAML; avoid creating UI in code. • Avoid using absolute positions and fixed sizes to lay out content; instead, use relative or automatic sizing. • Provide extra space in margins because localized text often requires more space. • Enable TextWrapping on TextBlock to avoid clipping. • Set the xml:lang attribute. • Changes the behavior of hyphenation, spell checking, number substitution, complex script shaping, and font fallback. 7 / 58
  8. 8. Localizing WPF Applications 1. Add a Uid property by running msbuild /t:updateuid ProjectName.csproj in a developer command shell. 2. Set <UICulture>en-US</UICulture> in your csproj file. 3. Build the application. 4. Download and build LocBaml from http://msdn.microsoft.com/en- us/library/vstudio/ms771568(v=vs.90).aspx 5. Run LocBaml /parse en-USProjectName.resources.dll at the location of the application binary (.exe). 6. Localize the resulting CSV file. 7. Generate new satellite assembly with LocBaml.exe /generate en-USProjectName.resources.dll /trans:ProjectName.resources.CSV /out: . /cul:de-DE 8. Copy resulting DLL to corresponding language folder. 8 / 58
  9. 9. LocBaml CSV Fields • BAML Name. The name of the BAML resource with respect to the source language satellite assembly. • Resource Key. The localized resource identifier. • Category. The value type. • Readability. Whether the value can be read by a localizer. • Modifiability. Whether the value can be modified by a localizer. • Comments. Additional description of the value to help determine how a value is localized. • Value. The text value to translate to the desired culture. 9 / 58
  10. 10. Gotcha! Both the LocBaml tool and your application must target the same platform and .NET framework! 10 / 78
  11. 11. Gotcha! The locale specified for the LocBaml tool and the localization folder must match! 11 / 78
  12. 12. Localizing the Level Editor DEMO 12 / 58
  13. 13. “How do you automate a client-server, distributed, persistent, sharded, asynchronous, realtime, scalable system?” 13 / 58
  14. 14. “How do you automate a client-server, distributed, persistent, sharded, asynchronous, realtime, scalable system?” “Very carefully.” - David Press, CCP Games 14 / 58
  15. 15. Unit Testing • Method by which individual units of source code are tested to determine if they are fit for use • Unit of source code is the smallest testable part of an application (e.g. method) • Created by programmers during the development process 15 / 58
  16. 16. Unit Testing • Ideally, each test case is independent from the others • Substitutes such as mocks can be used to assist testing a module in isolation (e.g. database, mails) • Can be implemented as part of automated builds 16 / 58
  17. 17. Advantages of Unit Testing  Finds problems early • Test Driven Development  Facilitates changes • Can be run before each commit or build • In combination with source control, can identify the revision (and originator) that broke the code 17 / 58
  18. 18. Limits of Unit Testing • Won’t catch every error in the program • Won’t catch integration errors • Combinatorial problem • Every boolean decision statement requires at least two tests • Can’t test non-deterministic or concurrency problems 18 / 58
  19. 19. Limits of Unit Testing • Setting up realistic and useful tests is a challenge • Test case failures need to be reviewed daily and addressed immediately • Embedded system software presents a unique challenge • Software is being developed on a different platform than the one it will eventually run on 19 / 58
  20. 20. Unit Testing with NUnit • Unit Testing framework for all .NET languages • Initially ported from JUnit • Written entirely in C# • Stand-alone tools and R# integration 20 / 58
  21. 21. Setting up NUnit 1. Add new Class Library project to the solution. 2. Add reference to bin/framework/nunit.framework.dll. 21 / 58
  22. 22. NUnit Test Class Design • Public • Default constructor 22 / 58
  23. 23. NUnit Test Method Design • [Test] attribute • Return void • No parameters 23 / 58
  24. 24. NUnit Test Example C# 24 / 58 namespace LevelEditor.Tests { using LevelEditor.Model; using NUnit.Framework; public class MapTest { [Test] public void TestMapConstructor() { // Create new map. const int Width = 32; const int Height = 16; Map map = new Map(Width, Height); // Check width and height. Assert.AreEqual(Width, map.Width); Assert.AreEqual(Height, map.Height); } } }
  25. 25. NUnit Assertions • AreEqual, AreNotEqual • AreSame, AreNotSame • IsTrue, IsFalse • Greater, GreaterOrEqual • Less, LessOrEqual • IsEmpty, IsNotEmpty • IsNull, IsNotNull • Contains • Fail, Inconclusive 25 / 58
  26. 26. Expected Exceptions C# 26 / 58 [Test] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void TestNegativeWidth() { Map map = new Map(-10, 20); }
  27. 27. SetUp and TearDown C# 27 / 58 public class MapTest { private const int Height = 16; private const int Width = 32; private Map map; [SetUp] public void SetUp() { this.map = new Map(Width, Height); } [Test] public void TestTileIndexer() { const int X = 1; const int Y = 2; var mapTile = new MapTile(X, Y, "Desert"); this.map[X, Y] = mapTile; Assert.AreEqual(mapTile, this.map[X, Y]); } }
  28. 28. Hint Override Equals in types whose objects you need to compare! 28 / 78
  29. 29. NUnit Test Tool 29 / 78
  30. 30. NUnit Console Console Output 30 / 58 D:DevRepositoriesSAE-ToolDevelopmentVendorNUnit-2.6.3bin>nunit-console-x86.exe ......SourceLevelEditor.TestsbinDebugLevelEditor.Tests.dll NUnit-Console version 2.6.3.13283 Copyright (C) 2002-2012 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved. Runtime Environment - OS Version: Microsoft Windows NT 6.2.9200.0 CLR Version: 2.0.50727.7905 ( Net 3.5 ) ProcessModel: Default DomainUsage: Single Execution Runtime: net-3.5 ... Tests run: 3, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.046059608766156 seconds Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
  31. 31. NUnit & Visual Studio 31 / 78
  32. 32. NUnit & Visual Studio 32 / 78
  33. 33. Test Driven Development 1. Write an (initially failing) automated test case that defines a desired improvement or new function. 2. Produce the minimum amount of code required to pass that test. 3. Refactor the new code to acceptable standards. 33 / 58
  34. 34. Advantages of TDD  Client-first development  Taking small steps  All written code is covered by at least one test  Can lead to more modularized code 34 / 58
  35. 35. Limits of TDD • Support of the entire team is essential • Test are typically created by the developer who is writing the code being tested, and may therefore share the same blind spots with the code • Maintenance overhead 35 / 58
  36. 36. Assignment #9 Unit Tests 1. Download NUnit from http://nunit.org/index.php?p=download and add it to your project. 2. Write a unit test asserting the construction of maps with correct width and height. 3. Write a unit test asserting the failure of construction of maps with negative width or height. 36 / 58
  37. 37. References • MSDN. WPF Globalization and Localization Overview. http://msdn.microsoft.com/en- us/library/ms788718(v=vs.110).aspx, June 2014. • MSDN. How to: Localize an Application. http://msdn.microsoft.com/en- us/library/ms746621(v=vs.110).aspx, June 2014. • Wikipedia. Unit testing. http://en.wikipedia.org/wiki/Unit_testing, December 12, 2013. • Poole. Getting Started with Nunit. http://www.nunit.org/index.php?p=getStarted&r=2.6.3, June 2014. • Wikipedia. Test-driven development. http://en.wikipedia.org/wiki/Test-driven_development, December 14, 2013. 37 / 58
  38. 38. Thank you for your attention! Contact Mail dev@npruehs.de Blog http://www.npruehs.de Twitter @npruehs Github https://github.com/npruehs 38 / 58
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×