The Testability Explorer Blog
By Thomas Johnson | July 8, 2009
We are going to start doing test driven development at my work. So I’ve been looking at ways around the problems that I’ve previously encountered when trying to write unit tests. Most of these problems centre around not being able to isolate the logic that I want to test. Often there are large amounts of objects to setup first and quite often database fields are required as well.
I’ve found Misko Hervery’s testability blog to be quite useful for understand these problems and finding some solutions. The following articles are good starting points:
Top 10 things which make your code hard to test
Topics: Coding Style, unit testing | No Comments »
Profiling .NET CF Applications With Eqatec
By Thomas Johnson | April 28, 2009
Today I found the Eqatec Profiler application which is a .NET profiler that works on compact framework applications. It’s quite easy to setup and it’s free. The interface for viewing the results is also very good allowing you to easily find the methods that are causing problems.
What Is A Profiler?
A profiler is a tool that allows you to examine your application to see which methods are running slowly. This allows you to spend your time optimising the methods that need it the most. Otherwise you can waste a lot of time optimising code that isn’t really causing the problem.
Profiling CF Applications On Mobile Devices
Eqatec is one of the only profilers that will work with CF application on mobile devices. Profiling is particularly useful on mobile devices due to their reduced memory and processing power. After running the profiler on a CF project I was able to easily reduce the application startup time by 25%.
Here is a basic guide to getting Eqatec working with a CF application.
1. Download The Eqatec Profiler


2. Setup the application in Eqatec
3. Build profiled version of your application
4. Deploy profiled version of the mobile device
This can be done using windows explorer or you can make it a little easier by setting up a bat file that uses CE Copy like this:
“C:\Program Files\Windows Mobile Developer Power Toys\CECopy\CECopy.exe” “C:\AppFolder\bin\Debug-Profiled\*.*” “dev:\Program Files\App Profiled”
5. Run your application and exercise the required features
You need to make sure you are running the profiled version of your app that was built by Eqatec. Once you’ve exercised the required features and closes the application a log/report file should be generated in “dev:\Temp\EQATECProfilerLogs”.
6. Copy the profiler generated log file from the mobile device to the PC
Again CE copy can be used here, the command for the default directories is:
“C:\Program Files\Windows Mobile Developer Power Toys\CECopy\CECopy.exe” “dev:\Temp\EQATECProfilerLogs” “C:\WINDOWS\Temp\EQATECProfilerLogs”
7. Analyse the log files in the Eqatec software
Topics: General | No Comments »
Quickly Copy Files Between Mobile Device And Desktop PC
By Thomas Johnson | April 28, 2009
Often I find myself repeatedly copying files between a mobile device and desktop pc. Using the CE Copy tool that is part of the Windows Mobile Developer Power Toys it is quite easy to setup up a bat file to make this task easier.
After you’ve installed the power toys it’s a simple matter of setting up a bat file with the following command. Just replace the ??? with the directories or files that you’re interested in.
To copy from the device:
“C:\Program Files\Windows Mobile Developer Power Toys\CECopy\CECopy.exe” “dev:\???” “C:\???”
To copy to the device:
“C:\Program Files\Windows Mobile Developer Power Toys\CECopy\CECopy.exe” “C:\???” “dev:\???”
Topics: Uncategorized | 1 Comment »
Identifying Duplicate Code With Simian
By Thomas Johnson | April 13, 2009
I’ve recently discovered the tool Simian which you can use to identify blocks of duplicate code. I’ve been experimenting with it on C# code but Simian should work in pretty much any programming language.
Reduction of duplication within code is widely accepted as a worthwhile goal as it makes your code easier to debug, maintain and extend. A tool like Simian makes it possible to easily locate duplicated code within different files or even projects. Once you’ve found the duplicate code it is often quite easy to create a common method or class to remove the duplication.
Simian Similarity Analyser - Homepage
Topics: Coding Style, Productivity | 2 Comments »
Speeding up builds in Visual Studio for .net CE
By Thomas Johnson | April 8, 2009
Finally I’ve found a way to reduce the compile time for the windows mobile app that I’m working on. The compile time reduced from around 50 seconds to less than 5!! This has certainly made my work more enjoyable and productive.
To do it you need to disable the Platform Verification Task. Just follow these steps.
- Edit %windir%\Microsoft.NET\Framework\%latest version of framework%\Microsoft.CompactFramework.Common.Targets
- Find the line which reads: Name=”PlatformVerificationTask”>
- Change it to: Name=”PlatformVerificationTask” Condition=”false”
- Restart Visual Studio
You should be able to use an environmental variable in the condition but I couldn’t get that to work.
It sounds like it would pay to do the occasional build with platform verification on especially before doing a release.
Topics: Productivity | 3 Comments »
NUnit TestCase
By Thomas Johnson | March 3, 2009
In my previous post about fitnesse I mentioned that it would be good to have a simple way to specify expected inputs and outputs for a method. I was fairly sure there must be something out there and the latest version of NUnit (Beta version 2.5) offers a great solution.
It allows us to specify parameters for a test method in a way which provides great flexibility. Here you can see how easily we’re able to supply the data for different test cases … the tests run as if you had set up seperate methods for each case.
You can also use a result parameter to specify an expected return value as follows: This is great … a clear and concise way to setup multiple test cases for simple tests. If the test setup is more complicated it may not workout out so nicely. I believe other unit test frameworks provide similar functionality so have a look around. Topics: Coding Style, unit testing | No Comments » By Thomas Johnson | February 23, 2009 I’ve recently been experimenting a bit with Fitnesse, an automated testing tool that uses a wiki to specify and document the tests. It’s java code that runs as a service but you can easily test code from other languages such as .net, delphi and more. Fitnesse tests are setup in a table format which is very convenient if you need to try out a lot of different parameter values and combinations. Check out the division example on the fitnesse site for an example test page. I’ve often thought that tables would make a good way to specify tests and this implementation seems to work quite well, although I had a few minor difficulties getting it setup. One cool thing here is that in many cases you don’t need to be a developer to add test cases once the first few have been setup. So if someone comes up with a combination of parameters that haven’t been tested they can add the new case without needing a developer. I wouldn’t say this is something amazing which everyone should start using immediately, but it could definitely be quite useful so it’s worth a look. I think perhaps the use of a wiki and the plumbing that is required to link it to test methods seems a bit cumbersome. Some sort of framework that provides an easy way to run tests against parameter lists that have been specified in csv format would be good, that way you could drive everything from a standard unit testing tool like nunit. Leave a comment if you’ve come across something like that otherwise I may look into creating one. Topics: unit testing | 1 Comment » By Thomas Johnson | January 29, 2009 Ever since I started working with dual monitors I’ve always found it suprising that there is no easy way to move a maximised window from one monitor to the other in windows. You have to “restore” the window drag to the other monitor and then maximise again. I’ve found a pretty good solution for this check out Winsplit Revolution. Just install it and then use ctrl+alt+left/right to move the active window between screens. You can also do some cool stuff like resizing a window to only take up the top half of the screen using ctrl+alt+numpad 8 or left with numpad 4. It’s a fairly intuitive set of hotkeys. So Winsplit is a great little app and it’s free too! If it continues to work well for me I’ll probably make a donation. Topics: Productivity | No Comments » By Thomas Johnson | January 29, 2009 I had quite a few troubles getting set up for unit testing of mobile device applications. I was trying to write tests for the compact framework on Windows Mobile 5. I did eventaully get the tests up and running with the device emulator, but the tests where terribly slow to run, it was taking about 5 seconds per test. At this speed unit testing is crippled so much that it becomes useless. So I sought out a way to run the tests without needing to use the device or an emulator. Turns out that a combination of NUnit and TestDriven.net makes for a pretty good solution. Can run a whole bunch of tests in 0.3 seconds … much faster that running through the device emulator! TestDriven.net is an extension for visual studio that adds an option to run tests into the right click menu. You can choose a test method, class or entire solution and then right click and say run tests. By default it will just show a text summary of the test results but you use test with -> NUnit if you want to see the results in the GUI. One advantage of the NUnit gui over the text summary is that you can easily see which tests have failed. Here’s a sample of some NUnit tests: Topics: unit testing | No Comments » By Thomas Johnson | January 28, 2009 The simplest way to run a shell command in c# is as follows: Topics: linux | No Comments »
</code></code></code>
[TestFixture]
public class StringFormatUtilsTest
{
[TestCase("tttt", "")]
[TestCase("", "")]
[TestCase("t3a4b5", "345")]
[TestCase("3&amp;5*", "35")]
[TestCase("123", "123")]
public void StripNonNumeric(string before, string expected)
{
string actual = FormatUtils.StripNonNumeric(before);
Assert.AreEqual(expected, actual);
}
}
</code></code></code>
[TestFixture]
public class StringFormatUtilsTest
{
[TestCase("tttt", Result="")]
[TestCase("", Result="")]
[TestCase("t3a4b5", Result="345")]
[TestCase("3&amp;5*", Result="35")]
[TestCase("123", Result="123")]
[TestCase("asf", Result="a")]
public string StripNonNumeric(string before)
{
return FormatUtils.StripNonNumeric(before);
}
}
Automated Testing With Fitnesse
Making Better Use Of Multiple Monitors
Unit Testing Of Mobile Device Applications
</code></code>
using StringUtils;
using NUnit.Framework;
namespace StringUtilTesting
{
[TestFixture]
public class StringUtilsTest
{
public void StripNonNumericEmpty()
{
string text = string.Empty;
string expected = string.Empty;
string actual;
actual = StringUtils.StripNonNumeric(text);
Assert.AreEqual(expected, actual);
}
[Test]
public void StripNonNumericNoNumbers()
{
string text = "tttt";
string expected = string.Empty;
string actual;
actual = StringUtils.StripNonNumeric(text);
Assert.AreEqual(expected, actual);
}
[Test]
public void StripNonNumericMixed()
{
string text = "t3a4b5";
string expected = "345";
string actual;
actual = StringUtils.StripNonNumeric(text);
Assert.AreEqual(expected, actual);
}
}
}
<code>
Shell Commands In C#
System.Diagnostics.Process.Start("festival --tts hello.txt");