AppVeyor单元测试失败,因为未创建目录

时间:2019-04-21 13:43:31

标签: c# xunit.net appveyor

即使在本地计算机上成功运行,单元测试JsonStorageTest()每次在AppVeyor上构建时也会失败。

   [Fact]
    public static void JsonStorageTest()
    {
        const string expected = "I'm a unit test!";
        const string expectedKey = "xUnitTests/TEST";

        IDataStorage storage = new JsonStorage();

        storage.StoreObject(expected, expectedKey);

        var actual = storage.RestoreObject<string>(expectedKey);

        Assert.Equal(expected, actual);
     }

我使用RDP登录到AppVeyor运行的虚拟机中,我注意到Appveyor不会创建任何目录,因此测试自然会失败。 此错误也显示在[AppVeyor构建日志]中,这就是我使用RDP查找错误的原因。

    public void StoreObject(object obj, string key)
    {
        var file = $"{key}.json";
        CreateDirectory(Path.GetDirectoryName(file));
        var json = JsonConvert.SerializeObject(obj);
        File.WriteAllText(file, json);
    }

这是通常应创建目录的方法,但如上所述,AppVeyor不能这样做。 我希望这样的问题不存在(我搜索了很长时间,但是没有找到解决方案),并且该问题不是我自己无法编写适当的代码引起的。 有人能指出我正确的方向吗?

PS:这里是repo link(如果有帮助的话)。

0 个答案:

没有答案