This document discusses localization and testing for WPF applications. It begins by explaining the differences between globalization and localization, with globalization referring to making applications work in multiple locations and localization being the translation of resources. It then provides best practices for WPF UI design to support localization. The document outlines the process for localizing WPF applications using the LocBaml tool to extract and replace resources. It also discusses unit testing WPF applications using the NUnit framework, including test design, assertions and attributes. The document notes advantages and limitations of both unit testing and test-driven development (TDD).
3. Objectives
• To understand how to globalize and localize WPF
applications
• To learn how to properly set up automatic testing
for your WPF applications
3 / 58
4. 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.
4 / 58
5. 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.
5 / 58
6. 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.
6 / 58
7. 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 some PropertyGroup of 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.
7 / 58
8. 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.
8 / 58
9. Gotcha!
Both the LocBaml tool and your
application must target the same
platform and .NET framework!
9 / 78
12. “How do you automate a client-server, distributed,
persistent, sharded, asynchronous, realtime, scalable
system?”
12 / 58
13. “How do you automate a client-server, distributed,
persistent, sharded, asynchronous, realtime, scalable
system?”
“Very carefully.”
- David Press, CCP Games
13 / 58
14. 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
14 / 58
15. 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
15 / 58
16. 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
16 / 58
17. 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
17 / 58
18. 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
18 / 58
19. 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
19 / 58
20. Setting up NUnit
1. Add new Class Library project to the solution.
2. Add reference to
bin/framework/nunit.framework.dll.
20 / 58
22. NUnit Test Method Design
• [Test] attribute
• Return void
• No parameters
22 / 58
23. NUnit Test Example
C#
23 / 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. Expected Exceptions
C#
25 / 58
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestNegativeWidth()
{
Map map = new Map(-10, 20);
}
26. SetUp and TearDown
C#
26 / 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]);
}
}
29. NUnit Console
Console Output
29 / 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
32. 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.
32 / 58
33. 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
33 / 58
34. 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
34 / 58
35. 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.
35 / 58
36. References
• MSDN. WPF Globalization and Localization Overview.
http://msdn.microsoft.com/en-
us/library/ms788718(v=vs.110).aspx, May 2016.
• MSDN. How to: Localize an Application.
http://msdn.microsoft.com/en-
us/library/ms746621(v=vs.110).aspx, May 2016.
• 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, May
2016.
• Wikipedia. Test-driven development.
http://en.wikipedia.org/wiki/Test-driven_development,
December 14, 2013.
36 / 58
38. 5 Minute Review Session
• What is the difference between Globalization and
Localization?
• Name a few globalization best practices!
• What are the main advantages of unit testing?
• What are the most important limits of unit tests?
• Explain the process of Test Driven Development!
• What are the upsides and downsides of TDD?
38 / 58