Ich versuche, eine Datei (Account.cs) mit testfile (AccountTest.cs) zu testen. Ich betreibe OSX 10.6 mit Mono Framework (und Nunit-Konsole).Code Coverage mit Mono- und Nunit-Tests
Unten ist Account.cs
namespace bank
{
using System;
public class InsufficientFundsException : ApplicationException
{
}
public class Account
{
private float balance;
public void Deposit(float amount)
{
balance+=amount;
}
public void Withdraw(float amount)
{
balance-=amount;
}
public void TransferFunds(Account destination, float amount)
{
destination.Deposit(amount);
Withdraw(amount);
}
public float Balance
{
get { return balance;}
}
private float minimumBalance = 10.00F;
public float MinimumBalance
{
get{ return minimumBalance;}
}
}
}
Und hier ist AccountTest.cs:
namespace bank
{
using NUnit.Framework;
[TestFixture]
public class AccountTest
{
[Test]
public void TransferFunds()
{
Account source = new Account();
source.Deposit(200.00F);
Account destination = new Account();
destination.Deposit(150.00F);
source.TransferFunds(destination, 100.00F);
Assert.AreEqual(250.00F, destination.Balance);
Assert.AreEqual(100.00F, source.Balance);
}
[Test]
[ExpectedException(typeof(InsufficientFundsException))]
public void TransferWithInsufficientFunds()
{
Account source = new Account();
source.Deposit(200.00F);
Account destination = new Account();
destination.Deposit(150.00F);
source.TransferFunds(destination, 300.00F);
}
}
}
ich diese beiden Dateien kompilieren:
mcs -t:library Account.cs
mcs -t:library -r:nunit.framework,Account.dll AccountTest.cs
und erhalten Konto .dll und AccountTest.dll jeweils.
den Test verwende ich auszuführen:
nunit-console AccountTest.dll
und es läuft, wie es sollte, mir die entsprechenden Ausfälle geben und Pässe.
Aber jetzt möchte ich mono's Code-Coverage-Fähigkeit verwenden, um diese Tests zu beurteilen. Ich lese das Tutorial http://mono-project.com/Code_Coverage, um die Coverage-Tools auszuführen. Und um es zu verwenden, müsste ich eine * .exe-Datei anstelle einer * .dll-Datei kompilieren.
Wenn jemand mir mit der Hauptklasse der Datei AccountTest.cs helfen könnte, wäre ich in der Lage, es in exe zu kompilieren und von dort das Coverage-Tool zu verwenden.
Vielen Dank im Voraus.