此方法有效(它创建一个传入字符串的目录):
internal static void ConditionallyCreateDirectory(string dirName)
{
Directory.CreateDirectory(dirName);
}
...但是,根据我的OCDish倾向,我正在测试所有方法"以防万一&#34 ;;我在我的测试项目中得到了这个测试:
[TestMethod]
public void TestConditionallyCreateDirectory()
{
string testDirName = "testDir";
RoboReporterConstsAndUtils.ConditionallyCreateDirectory(testDirName);
bool dirCreated = System.IO.File.Exists(string.Format("C:\\{0}", testDirName));
// also tried @"C:\{0}" and @"C:\\{0}"
Assert.IsTrue(dirCreated);
}
但它失败了; dirCreated不是真的。为什么?我不能(显然)进入方法,看看到底发生了什么,以及"失败"消息告诉我除了" Assert.IsTrue失败":
为什么会失败(鱼),我怎样才能确定它失败的原因(教鱼)?
我现在也尝试了以下各项:
bool dirCreated = System.IO.Directory.Exists(string.Format("C:\\{0}", testDirName));
bool dirCreated = System.IO.Directory.Exists(string.Format(@"C:\{0}", testDirName));
bool dirCreated = System.IO.Directory.Exists(string.Format(@"C:\\{0}", testDirName));
答案 0 :(得分:0)
你必须这样写:
public static void main(String[] args) throws IOException {
InputStream propertiesStream = DCGSGenerator.class.getClassLoader().getResourceAsStream("ezbake-config.properties");
Properties properties = new Properties();
properties.load(propertiesStream);
DCGSGenerator gen = new DCGSGenerator(
properties.getProperty("dcgs.input.sftp.host"),
properties.getProperty("dcgs.input.sftp.username"),
null,//properties.getProperty("dcgs.input.sftp.password", null),
properties.getProperty("dcgs.input.sftp.keyfile", null),
22,
properties.getProperty("dcgs.input.sftp.path")
);
gen.generate();
}