我正在使用内容控件和OpenXML SDK实现MS Word文档生成。我想为该代码编写一些自动化测试(单元测试或一些简单的UI自动化测试)。
有人有测试MS Word文档生成的经验吗?可能有哪些选项?
提前感谢!
我正在使用内容控件和OpenXML SDK实现MS Word文档生成。我想为该代码编写一些自动化测试(单元测试或一些简单的UI自动化测试)。
有人有测试MS Word文档生成的经验吗?可能有哪些选项?
提前感谢!
我实际上在使用OpenXML SDK处理电子表格,为了测试目的,我只需编写OpenXML API代码打开流中的文件。单元测试并不能告诉你足够多的信息,因为你需要知道文件是否有效。
// There should be a sheet for every team
[TestMethod]
[HostType("Moles")]
public void CaseExportTeamSheetsTest()
{
IRepository<ServiceTbl, ServiceTbl> ServiceRepository;
CaseController target;
BuildCaseControllerMoledCases(out ServiceRepository, out target);
FileStreamResult actual = target.Export(); using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(actual.FileStream, false))
{
var services = ServiceRepository.All;
foreach (var item in services)
{
// get a worksheet foreach service
var sheets = spreadsheetDocument.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == item.ServiceName);
Assert.IsTrue(sheets.Count() > 0);
}
}
actual.FileStream.Close();
actual.FileStream.Dispose();
}
关于OpenXml Sdk 2.0和有效代码的警告...
我使用XML SDK 2.0工具生成了符合验证的OpenXml Powerpoints文档,并且在我的PC上使用Office 2007可以正常工作,但是在另一台使用Office Powerpoint 2007的机器上打开文档时会出现格式无效的错误。
XML Sdk 2.0 http://www.microsoft.com/downloads/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en
测试 Microsoft Word 文档生成的高级方法如下:
定义测试用例,其中每个测试用例包括:
编写测试方法,使用您喜欢的单元测试框架(例如 xUnit)。使用典型的“安排、执行、断言”模式,这些测试方法:
使用 Open XML SDK 很容易检索实际的生成器输出。在比较实际和期望的输出时,您可以应用不同级别的标记过滤或简化。例如,您可以专注于基本标记,如问题中提到的内容控件(w:sdt
元素)。