Kelly Anderson
2008-03-25 23:13:33 UTC
The attachment bounced from the nunit-developer listserv... don't know
if it got through to NunitV3 or not. Sorry if this is a multiple
posting. I sent the attachment to Charlie directly...
-Kelly
As promised, I have attached my implementation of Assume. I did this
with the absolute minimum possible changes to the other files, so the
implementation is not optimal yet. It does, however, work for regular
Assume. I did not bother yet to do Collections, Strings or File
Assumes to match the corresponding Asserts.... not sure if those are
useful or not.
These files were modified (slightly):
NUnitFramework.cs
Added:
public static readonly string AssumptionException =
"NUnit.Framework.AssumptionException";
NUnitTestMethod.cs
Added:
protected override bool IsAssumeException(Exception ex)
{
return ex.GetType().FullName ==
NUnitFramework.AssumptionException;
}
TestMethod.cs
Changed:
protected internal virtual void ProcessException(Exception
exception, TestCaseResult testResult)
{
if (!ExceptionExpected)
{
RecordException(exception, testResult);
return;
}
To:
protected internal virtual void ProcessException(Exception
exception, TestCaseResult testResult)
{
if (IsAssumeException(exception))
{
// TODO: Perhaps add text to some output stream.
testResult.Success();
return;
}
if (!ExceptionExpected)
{
RecordException(exception, testResult);
return;
}
nunit.framework.dll_VS2005.csproj
Added references to new files:
<Compile Include="Assume.cs" />
<Compile Include="AssumptionException.cs" />
Assume.cs - New File
AssumptionException.cs - New File
nunit.framework.tests_VS2005.csproj
Added reference to new file:
<Compile Include="AssumptionTest.cs" />
AssumptionTest.cs - Added
===================
Assume works just like Assert, except that it throws a different exception.
I would propose refactoring this code, pushing up a common base class
(Perhaps called AssBase? :-) that is inherited by both Assume and
Assert. Everything is moved up there, except that there is a new
virtual function called ThrowException which either throws
AssertException or AssumeException in either subclass. Wherever the
Exception is thrown in the base class, call ThrowException. Then I
think it's nicely done.
I didn't do that already because I wanted to make merging the code in
very easy for anyone wanting to experiment.
Charlie, please feel free to add this to the code base if you like it.
Obviously, I'd rather do the suggested refactoring first, of course.
The question of where to put the Assume message output is obviously up
for discussion. I did not implement anything relating to multiple
invocations of a test, including not passing the test if it always
fires Assume.
On a side note, this is only the second time I've modified code
written by someone else under test. What a pleasure!! Even though I
did have to resort to using the Debugger to figure out how the
exceptions were handled :-)
-Kelly
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
if it got through to NunitV3 or not. Sorry if this is a multiple
posting. I sent the attachment to Charlie directly...
-Kelly
As promised, I have attached my implementation of Assume. I did this
with the absolute minimum possible changes to the other files, so the
implementation is not optimal yet. It does, however, work for regular
Assume. I did not bother yet to do Collections, Strings or File
Assumes to match the corresponding Asserts.... not sure if those are
useful or not.
These files were modified (slightly):
NUnitFramework.cs
Added:
public static readonly string AssumptionException =
"NUnit.Framework.AssumptionException";
NUnitTestMethod.cs
Added:
protected override bool IsAssumeException(Exception ex)
{
return ex.GetType().FullName ==
NUnitFramework.AssumptionException;
}
TestMethod.cs
Changed:
protected internal virtual void ProcessException(Exception
exception, TestCaseResult testResult)
{
if (!ExceptionExpected)
{
RecordException(exception, testResult);
return;
}
To:
protected internal virtual void ProcessException(Exception
exception, TestCaseResult testResult)
{
if (IsAssumeException(exception))
{
// TODO: Perhaps add text to some output stream.
testResult.Success();
return;
}
if (!ExceptionExpected)
{
RecordException(exception, testResult);
return;
}
nunit.framework.dll_VS2005.csproj
Added references to new files:
<Compile Include="Assume.cs" />
<Compile Include="AssumptionException.cs" />
Assume.cs - New File
AssumptionException.cs - New File
nunit.framework.tests_VS2005.csproj
Added reference to new file:
<Compile Include="AssumptionTest.cs" />
AssumptionTest.cs - Added
===================
Assume works just like Assert, except that it throws a different exception.
I would propose refactoring this code, pushing up a common base class
(Perhaps called AssBase? :-) that is inherited by both Assume and
Assert. Everything is moved up there, except that there is a new
virtual function called ThrowException which either throws
AssertException or AssumeException in either subclass. Wherever the
Exception is thrown in the base class, call ThrowException. Then I
think it's nicely done.
I didn't do that already because I wanted to make merging the code in
very easy for anyone wanting to experiment.
Charlie, please feel free to add this to the code base if you like it.
Obviously, I'd rather do the suggested refactoring first, of course.
The question of where to put the Assume message output is obviously up
for discussion. I did not implement anything relating to multiple
invocations of a test, including not passing the test if it always
fires Assume.
On a side note, this is only the second time I've modified code
written by someone else under test. What a pleasure!! Even though I
did have to resort to using the Debugger to figure out how the
exceptions were handled :-)
-Kelly
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace