SUT 无法在编码测试中保存文件 UI
SUT cannot save file in coded test UI
我是 visual studio 2013 年编码 ui 测试的新手。
我正在尝试测试读取文件、执行操作并保存该文件的程序的一部分。手动测试,没有问题。使用编码ui测试,程序可以读取文件但不能保存。
存在非托管异常"System.IO.IOException: the process cannot access the file '...\tempData.xml', because it is being used by another process."
当我在异常框中单击"continue",并重新单击保存文件的按钮时,不再有异常并且文件被保存。很奇怪。
好像我的测试在 SUT 使用文件时访问了文件
我的测试:
[TestInitialize]
public void RunApp()
{
_sut = ApplicationUnderTest.Launch(Settings.Default.pathSut);
}
[TestMethod]
public void CompleteExport()
{
this.UiMap.ExportDataComplete(); //Read and save the file
this.UIMap.AssertSuccessExport();
}
以及我保存文件的方法:
public void TrySave()
{
string executableFolderPath = Environment.CurrentDirectory;
string path = executableFolderPath + "\" + Resources.xmlFile;
bool result = this.ValidateXml();
if (result)
XmlFic.Save(path);
}
我该如何解决?
我的缺点:
XmlReaderSettings settings = new XmlReaderSettings();
string executableFolderPath = Environment.CurrentDirectory;
string pathXsd = executableFolderPath + "\" + Resources.pathXsd;
string pathXml = executableFolderPath + "\" + Resources.xmlFile;
settings.Schemas.Add("", pathXsd);
settings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(pathXml, settings);
XmlFic = new XmlDocument();
XmlFic.Load(reader);
忘记了:
reader.Close();
奇怪的行为,为什么它在手动测试中工作?也许 GC 有时间处理它,而没有时间进行自动化测试?问题已解决,但如果有人有解释...
谢谢
我是 visual studio 2013 年编码 ui 测试的新手。
我正在尝试测试读取文件、执行操作并保存该文件的程序的一部分。手动测试,没有问题。使用编码ui测试,程序可以读取文件但不能保存。
存在非托管异常"System.IO.IOException: the process cannot access the file '...\tempData.xml', because it is being used by another process."
当我在异常框中单击"continue",并重新单击保存文件的按钮时,不再有异常并且文件被保存。很奇怪。
好像我的测试在 SUT 使用文件时访问了文件
我的测试:
[TestInitialize]
public void RunApp()
{
_sut = ApplicationUnderTest.Launch(Settings.Default.pathSut);
}
[TestMethod]
public void CompleteExport()
{
this.UiMap.ExportDataComplete(); //Read and save the file
this.UIMap.AssertSuccessExport();
}
以及我保存文件的方法:
public void TrySave()
{
string executableFolderPath = Environment.CurrentDirectory;
string path = executableFolderPath + "\" + Resources.xmlFile;
bool result = this.ValidateXml();
if (result)
XmlFic.Save(path);
}
我该如何解决?
我的缺点:
XmlReaderSettings settings = new XmlReaderSettings();
string executableFolderPath = Environment.CurrentDirectory;
string pathXsd = executableFolderPath + "\" + Resources.pathXsd;
string pathXml = executableFolderPath + "\" + Resources.xmlFile;
settings.Schemas.Add("", pathXsd);
settings.ValidationType = ValidationType.Schema;
XmlReader reader = XmlReader.Create(pathXml, settings);
XmlFic = new XmlDocument();
XmlFic.Load(reader);
忘记了:
reader.Close();
奇怪的行为,为什么它在手动测试中工作?也许 GC 有时间处理它,而没有时间进行自动化测试?问题已解决,但如果有人有解释...
谢谢