public class TestsForWhatever
{
public TestsForWhatever()
{
// You get one of these per test method, yay!
}
[TestInitialize]
public void Initialize()
{
// and one of these too!
}
[TestMethod]
public void AssertItDoesSomething() { }
[TestMethod]
public void AssertItDoesSomethingElse() { }
}
[Subject(typeof(Whatever))]
public class When_doing_whatever
{
Establish context = () =>
{
// one of these for all your Its
};
Because of = () => _subject.DoWhatever();
It should_do_something;
It should_do_something_else;
}
private readonly IDebuggingService debuggingService;
public string StepName { get; set; }
public DebuggingStep(IDebuggingService _debuggingService)
{
_log.Starting();
StepName = "DebuggingStep";
debuggingService = _debuggingService
?? throw new ArgumentException("DebuggingStep init failure due to => IDebuggingService null");
}
单元测试看起来像这样
[Fact]
public void TestDebuggingStepConstructorWhen_InitServiceIsNull_ResultArgumentException()
{
//Arrange
var arrange = new Action(() =>
{
new DebuggingStep(null);
});
//Act
//Arrange
Assert.Throws<ArgumentException>(arrange);
}