我注意到,为了对我的 OO 代码中的每个单元进行单元测试,我需要将访问修饰符设置为 public,即使在应该受到保护的方法上,或者可能是私有的。这是好的做法吗?
public class EnforceBusinessRules
{
BusinessState m_state;
public EnforceBusinessRules()
{
m_state = START;
}
public bool isInputcurrentlyFormatted(string input)
{
//code goes here to ensure the input passes formatting test
//modify m_state appropriately
}
public bool InputContainsValidStartAndEndTokens(string input)
{
//code goes here to ensure that the start and end tokens of the input are of the type available in the system
//modify m_state appropriately
}
public bool StartEndCommandisValidAccordingtoCurrentSystemSettings(string input)
{
//code goes here to check the start and End codes match the current start and end codes for the day
//modify m_state appropriately
}
// and so on
}