考虑下面需要测试的类,
class ToBeTested
{
Employee _e;
public ToBeTested(Employee e)
{
_e = e;
}
void Process()
{
// Do something with _e
}
}
[TestClass]
class ToBeTestedTest
{
[TestMethod]
public void TestProcessMethod()
{
Employee e = // Initialise it with some test value..
ToBeTested tbt = new ToBeTested(e);
tbt.Process();
//Assert to Verify the test results...
}
Run Code Online (Sandbox Code Playgroud)
问题Employee实际上可能是一个非常复杂的类型,其中包含属性,它们本身可以是更多类的对象.使用模拟值初始化Employee并生成可测试对象变得很困难.
在调试时,我可以设置断点并查看包含的Employee对象ToBeTested.有没有办法可以在运行时获取此对象中的所有值并在我的测试方法中使用它?
考虑以下代码,
abstract class AbstractClass
{
public abstract void AbstractMethodA();
public void ConcreteMethodA()
{
//Some operation
ConcreteMethodB();
}
}
public void ConcreteMethodB()
{
//Huge code unrelated to this class
AbstractMethodA();
}
}
class DerivedClass : AbstractClass
{
public void AbstractMethodA()
{
//Some operation
}
}
Run Code Online (Sandbox Code Playgroud)
现在我希望将ConcreteMethodB()移动到单独的类中,并从抽象类中的方法ConcreteMethodA()调用它.但是由于ConcreteMethodB()使用DerivedClass中实现的抽象方法AbstractMethodA(),我无法从新类访问AbstractMethodA()方法?有关如何解决此问题的任何想法?