Skip to content

Commit 69d2e23

Browse files
author
Mark Gants
committed
Add updated version of SharpUnit from 20 August 2010
- Updated documentation. - Add additional tests to the Assert class. - Include file names and line numbers where tests failed in error output. - Update doxygen config settings.
1 parent f72f4f9 commit 69d2e23

File tree

12 files changed

+160
-88
lines changed

12 files changed

+160
-88
lines changed

SharpUnit.sln

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
Microsoft Visual Studio Solution File, Format Version 10.00
3-
# Visual Studio 2008
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpUnit", "SharpUnit\SharpUnit.csproj", "{18EF2A7C-3CF7-4308-AF54-263174D1649F}"
5-
EndProject
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpUnitTest", "SharpUnitTest\SharpUnitTest.csproj", "{FF49B3B5-2A90-4F81-B8B7-A67AD32BED2B}"
7-
EndProject
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
84
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D0D3EE86-724B-411E-877D-6D6A97FCBAAC}"
95
ProjectSection(SolutionItems) = preProject
106
LICENSE.txt = LICENSE.txt
117
README.txt = README.txt
128
EndProjectSection
139
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpUnit", "SharpUnit\SharpUnit.csproj", "{18EF2A7C-3CF7-4308-AF54-263174D1649F}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpUnitTest", "SharpUnitTest\SharpUnitTest.csproj", "{FF49B3B5-2A90-4F81-B8B7-A67AD32BED2B}"
13+
EndProject
1414
Global
1515
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1616
Debug|Any CPU = Debug|Any CPU
@@ -26,12 +26,10 @@ Global
2626
{FF49B3B5-2A90-4F81-B8B7-A67AD32BED2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
2727
{FF49B3B5-2A90-4F81-B8B7-A67AD32BED2B}.Release|Any CPU.Build.0 = Release|Any CPU
2828
EndGlobalSection
29-
GlobalSection(NestedProjects) = preSolution
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
3031
EndGlobalSection
3132
GlobalSection(MonoDevelopProperties) = preSolution
3233
StartupItem = SharpUnitTest\SharpUnitTest.csproj
3334
EndGlobalSection
34-
GlobalSection(SolutionProperties) = preSolution
35-
HideSolutionNode = FALSE
36-
EndGlobalSection
3735
EndGlobal

SharpUnit/SharpUnit.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -12,6 +12,10 @@
1212
<AssemblyName>SharpUnit</AssemblyName>
1313
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
15+
<FileUpgradeFlags>
16+
</FileUpgradeFlags>
17+
<OldToolsVersion>3.5</OldToolsVersion>
18+
<UpgradeBackupLocation />
1519
</PropertyGroup>
1620
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1721
<DebugSymbols>true</DebugSymbols>

SharpUnit/Src/Assert.cs

Lines changed: 80 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* @file Assert.cs
33
*
44
* Static assertion methods for verifying test expectations.
5-
* Each test throws a TestException if it fails.
5+
* NOTE: It is important that each test throw its own TestException if it fails,
6+
* as this gives us more accurate call stack reporting.
7+
*
68
*/
79

810
using System;
@@ -26,7 +28,7 @@ public static Exception ExpectedException
2628
/**
2729
* Set the exception that is expected to be triggered by a unit test case.
2830
*
29-
* @param Exception ex, the expection to expect.
31+
* @param ex, the expection to expect.
3032
*/
3133
public static void ExpectException(Exception ex)
3234
{
@@ -36,18 +38,23 @@ public static void ExpectException(Exception ex)
3638
/**
3739
* Throw an exception if the boolean expression is not true.
3840
*
39-
* @param bool boolean, the expression to test.
41+
* @param boolean, the expression to test.
4042
*/
4143
public static void True(bool boolean)
4244
{
43-
True(boolean, "Expected True, got False.");
45+
// If not true
46+
if (true != boolean)
47+
{
48+
// Test failed
49+
throw new TestException("Expected True, got False.");
50+
}
4451
}
4552

4653
/**
4754
* Throw an exception if the boolean expression is not true.
4855
*
49-
* @param bool boolean, boolean expression to evaluate.
50-
* @param string msg, error message to display if test fails.
56+
* @param boolean, boolean expression to evaluate.
57+
* @param msg, error message to display if test fails.
5158
*/
5259
public static void True(bool boolean, string msg)
5360
{
@@ -62,18 +69,23 @@ public static void True(bool boolean, string msg)
6269
/**
6370
* Throw an exception if the boolean expression is not false.
6471
*
65-
* @param bool boolean, the expression to test.
72+
* @param boolean, the expression to test.
6673
*/
6774
public static void False(bool boolean)
6875
{
69-
False(boolean, "Expected False, got True.");
76+
// If not false
77+
if (false != boolean)
78+
{
79+
// Test failed
80+
throw new TestException("Expected False, got True.");
81+
}
7082
}
7183

7284
/**
7385
* Throw an exception if the boolean expression is not false.
7486
*
75-
* @param bool boolean, boolean expression to evaluate.
76-
* @param string msg, error message to display if test fails.
87+
* @param boolean, boolean expression to evaluate.
88+
* @param msg, error message to display if test fails.
7789
*/
7890
public static void False(bool boolean, string msg)
7991
{
@@ -88,18 +100,23 @@ public static void False(bool boolean, string msg)
88100
/**
89101
* Throw an exception if the object is not null.
90102
*
91-
* @param Object obj, the object to test.
103+
* @param obj, the object to test.
92104
*/
93105
public static void Null(Object obj)
94106
{
95-
Null(obj, "Expected Null object, got " + obj);
107+
// If not null
108+
if (null != obj)
109+
{
110+
// Test failed
111+
throw new TestException("Expected Null object, got " + obj);
112+
}
96113
}
97114

98115
/**
99116
* Throw an exception if the object is not null.
100117
*
101-
* @param Object obj, the object to test.
102-
* @param string msg, error message to display if test fails.
118+
* @param obj, the object to test.
119+
* @param msg, error message to display if test fails.
103120
*/
104121
public static void Null(Object obj, string msg)
105122
{
@@ -114,18 +131,23 @@ public static void Null(Object obj, string msg)
114131
/**
115132
* Throw an exception if the object is null.
116133
*
117-
* @param Object obj, the object to test.
134+
* @param obj, the object to test.
118135
*/
119136
public static void NotNull(Object obj)
120137
{
121-
NotNull(obj, "The object is null.");
138+
// If null
139+
if (null == obj)
140+
{
141+
// Test failed
142+
throw new TestException("The object is null.");
143+
}
122144
}
123145

124146
/**
125147
* Throw an exception if the object is null.
126148
*
127-
* @param Object obj, the object to test.
128-
* @param string msg, error message to display if test fails.
149+
* @param obj, the object to test.
150+
* @param msg, error message to display if test fails.
129151
*/
130152
public static void NotNull(Object obj, string msg)
131153
{
@@ -140,8 +162,8 @@ public static void NotNull(Object obj, string msg)
140162
/**
141163
* Throw an exception if the two integers are not not equal.
142164
*
143-
* @param int wanted, the value we expected.
144-
* @param int got, the value we actually received.
165+
* @param wanted, the value we expected.
166+
* @param got, the value we actually received.
145167
*/
146168
public static void Equal(int wanted, int got)
147169
{
@@ -156,9 +178,9 @@ public static void Equal(int wanted, int got)
156178
/**
157179
* Throw an exception if the two integers are not not equal.
158180
*
159-
* @param int wanted, the value we expected.
160-
* @param int got, the value we actually received.
161-
* @param string msg, error message to display if test fails.
181+
* @param wanted, the value we expected.
182+
* @param got, the value we actually received.
183+
* @param msg, error message to display if test fails.
162184
*/
163185
public static void Equal(int wanted, int got, string msg)
164186
{
@@ -179,8 +201,8 @@ public static void Equal(int wanted, int got, string msg)
179201
* http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
180202
* http://realtimecollisiondetection.net/blog/?p=89
181203
*
182-
* @param float wanted, the value we expected.
183-
* @param float got, the value we actually received.
204+
* @param wanted, the value we expected.
205+
* @param got, the value we actually received.
184206
*/
185207
public static void Equal(float wanted, float got)
186208
{
@@ -201,9 +223,9 @@ public static void Equal(float wanted, float got)
201223
* http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
202224
* http://realtimecollisiondetection.net/blog/?p=89
203225
*
204-
* @param float wanted, the value we expected.
205-
* @param float got, the value we actually received.
206-
* @param string msg, error message to display if test fails.
226+
* @param wanted, the value we expected.
227+
* @param got, the value we actually received.
228+
* @param msg, error message to display if test fails.
207229
*/
208230
public static void Equal(float wanted, float got, string msg)
209231
{
@@ -218,8 +240,8 @@ public static void Equal(float wanted, float got, string msg)
218240
/**
219241
* Throw an exception if the two strings are not not equal.
220242
*
221-
* @param string wanted, the value we expected.
222-
* @param string got, the value we actually received.
243+
* @param wanted, the value we expected.
244+
* @param got, the value we actually received.
223245
*/
224246
public static void Equal(string wanted, string got)
225247
{
@@ -234,9 +256,9 @@ public static void Equal(string wanted, string got)
234256
/**
235257
* Throw an exception if the two strings are not not equal.
236258
*
237-
* @param string wanted, the value we expected.
238-
* @param string got, the value we actually received.
239-
* @param string msg, error message to display if test fails.
259+
* @param wanted, the value we expected.
260+
* @param got, the value we actually received.
261+
* @param msg, error message to display if test fails.
240262
*/
241263
public static void Equal(string wanted, string got, string msg)
242264
{
@@ -251,8 +273,8 @@ public static void Equal(string wanted, string got, string msg)
251273
/**
252274
* Throw an exception if the two bools are not not equal.
253275
*
254-
* @param bool wanted, the value we expected.
255-
* @param bool got, the value we actually received.
276+
* @param wanted, the value we expected.
277+
* @param got, the value we actually received.
256278
*/
257279
public static void Equal(bool wanted, bool got)
258280
{
@@ -267,9 +289,9 @@ public static void Equal(bool wanted, bool got)
267289
/**
268290
* Throw an exception if the two bools are not not equal.
269291
*
270-
* @param bool wanted, the value we expected.
271-
* @param bool got, the value we actually received.
272-
* @param string msg, error message to display if test fails.
292+
* @param wanted, the value we expected.
293+
* @param got, the value we actually received.
294+
* @param msg, error message to display if test fails.
273295
*/
274296
public static void Equal(bool wanted, bool got, string msg)
275297
{
@@ -285,33 +307,33 @@ public static void Equal(bool wanted, bool got, string msg)
285307
* Throw an exception if the exceptions do not match.
286308
* NOTE: We only test the type and message of the exceptions.
287309
*
288-
* @param Exception wanted, the exception we expected.
289-
* @param Exception got, the exception we actually caught.
310+
* @param wanted, the exception we expected.
311+
* @param got, the exception we actually caught.
290312
*/
291313
public static void Equal(Exception wanted, Exception got)
292314
{
293-
Equal(wanted, got, "Exceptions do not match.\n\tExpected " + wanted + ",\n\tGot " + got);
315+
// If types or messages not equal
316+
if ((wanted.GetType() != got.GetType()) ||
317+
(wanted.Message != got.Message))
318+
{
319+
// Test failed
320+
throw new TestException("Exceptions do not match.\n\tExpected " + wanted + ",\n\tGot " + got);
321+
}
294322
}
295323

296324
/**
297325
* Throw an exception if the exceptions do not match.
298326
* NOTE: We only test the type and message of the exceptions.
299327
*
300-
* @param Exception wanted, the exception we expected.
301-
* @param Exception got, the exception we actually caught.
302-
* @param string msg, error message to display if test fails.
328+
* @param wanted, the exception we expected.
329+
* @param got, the exception we actually caught.
330+
* @param msg, error message to display if test fails.
303331
*/
304332
public static void Equal(Exception wanted, Exception got, string msg)
305333
{
306-
// If types not equal
307-
if (wanted.GetType() != got.GetType())
308-
{
309-
// Test failed
310-
throw new TestException(msg);
311-
}
312-
313-
// If the messages do not match
314-
if (wanted.Message != got.Message)
334+
// If types or messages not equal
335+
if ((wanted.GetType() != got.GetType()) ||
336+
(wanted.Message != got.Message))
315337
{
316338
// Test failed
317339
throw new TestException(msg);
@@ -321,8 +343,8 @@ public static void Equal(Exception wanted, Exception got, string msg)
321343
/**
322344
* Throw an exception if the two objects are not not equal.
323345
*
324-
* @param object wanted, the value we expected.
325-
* @param object got, the value we actually received.
346+
* @param wanted, the value we expected.
347+
* @param got, the value we actually received.
326348
*/
327349
public static void Equal(Object wanted, Object got)
328350
{
@@ -337,9 +359,9 @@ public static void Equal(Object wanted, Object got)
337359
/**
338360
* Throw an exception if the two objects are not not equal.
339361
*
340-
* @param object wanted, the value we expected.
341-
* @param object got, the value we actually received.
342-
* @param string msg, error message to display if test fails.
362+
* @param wanted, the value we expected.
363+
* @param got, the value we actually received.
364+
* @param msg, error message to display if test fails.
343365
*/
344366
public static void Equal(Object wanted, Object got, string msg)
345367
{

0 commit comments

Comments
 (0)