|
Partner
|
|
|
Workaround für [ExpectedException(typeof(ContractException)]
Autor:
Rainer Hilmer
|
Sprache:
C#
|
Bewertung:
noch nicht bewertet
|
Anzahl der Aufrufe:
2035
|
Beschreibung:
Schreibt man Unit Tests für Methoden die mit CodeContracts ausgestattet sind ( http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx ), kann man das Attribut [ExpectedException(typeof(ContractException)] nicht verwenden weil ContractException internal ist. Dieses Snippet stellt eine funktionierende Alternative dar. Weitere Infos unter http://dotnet-forum.de/forums/t/1916.aspx
Abgelegt unter: TDD, Unit Tests, ExpectedException, ContractException, CodeContracts, Code Contracts.
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[TestMethod]
public void $GiveMeSomeName$()
{
var target = new $ClassUnderTest()$;
try
{
target.$MethodUnderTest()$;
}
catch(Exception exc)
{
Assert.IsTrue(exc.GetType().Name == "ContractException");
return;
}
Assert.Fail("ContractException has not been thrown.");
}
|
|
Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)
|
|
Diese Snippets könnten für Sie interessant sein:
|
|
|
| Keine Snippets verfügbar. |
|
|
|
|
|