Upload
nick-pruehs
View
752
Download
4
Tags:
Embed Size (px)
DESCRIPTION
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.
Citation preview
Tool DevelopmentChapter 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 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
Assignment Solution #8
DEMO
3 / 58
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
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
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
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
Localizing WPF Applications
1. Add a Uid property by running msbuild /t:updateuidProjectName.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-US\ProjectName.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-US\ProjectName.resources.dll /trans:ProjectName.resources.CSV /out: . /cul:de-DE
8. Copy resulting DLL to corresponding language folder.
8 / 58
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
Gotcha!
Both the LocBaml tool and yourapplication must target the same
platform and .NET framework!
10 / 78
Gotcha!
The locale specified for the LocBamltool 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 carefully.”
- David Press, CCP Games
14 / 58
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
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
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
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
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
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
Setting up NUnit
1. Add new Class Library project to the solution.
2. Add reference to bin/framework/nunit.framework.dll.
21 / 58
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 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);
}}
}
NUnit Assertions
• AreEqual, AreNotEqual
• AreSame, AreNotSame
• IsTrue, IsFalse
• Greater, GreaterOrEqual
• Less, LessOrEqual
• IsEmpty, IsNotEmpty
• IsNull, IsNotNull
• Contains
• Fail, Inconclusive
25 / 58
Expected Exceptions
C#
26 / 58
[Test]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestNegativeWidth()
{
Map map = new Map(-10, 20);
}
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]);}
}
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:\Dev\Repositories\SAE-ToolDevelopment\Vendor\NUnit-2.6.3\bin>nunit-console-x86.exe ..\..\..\Source\LevelEditor.Tests\bin\Debug\LevelEditor.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
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 function.
2. Produce the minimum amount of code required to pass that test.
3. Refactor the new code to acceptable standards.
33 / 58
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
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
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
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
Thank you for your attention!
Contact
Blog
http://www.npruehs.de
@npruehs
Github
https://github.com/npruehs
38 / 58