如何利用 TDD 删除 class 面向 API 的 public 部分?

How do I leverage TDD to remove parts of the public facing API of a class?

我有一个class像这样

public class Foo : ICompletable
{
    public IAmCompleted { get; set;} // from interface
   private IFooCollab collab;

  public Foo(IFooCollab collab)
{
  this.collab = collab;

}

 public YouCompleteMe()
{
  this.collab.command();
 this. IAmCompleted = true;

}

[TestFixture]
public class Tests
{
public void when_i_am_completed_then_completed_is_true()
{
  var   sut = new Foo(new mock<IFooColab>().object);
  Assert.That(sut.IsCompleted, Is.True);
}


[Test]
public void  when_i_am_completed_command_is_issued()
{
 var collabMock = new mock<IFooCollab>();
 ...sut blah
   collabMock.verify(x => x.command(), Times.Once)
}
}

删除接口和任何使用它的东西都是我需要做的。我什至应该如何从测试中驱动它。如果我删除测试,功能仍然存在。我几乎说相反,通过破坏产品代码来破坏测试:) grd.. green red delete

删除未使用的代码是重构步骤的一部分。如果代码确实不需要,您可以将其删除,运行 现有测试和一切都应该通过。