【问题标题】:How to reference LeadTools to Unit Test project?如何将 LeadTools 引用到单元测试项目?
【发布时间】:2013-06-22 03:28:58
【问题描述】:

评估文档成像 SDK,我正在尝试在我的 Visual Studio 2012 中创建一个单元测试项目来检查一些代码 sn-ps。我从安装目录“C:\LEADTOOLS 18\Bin\Dotnet4\Win32”中引用了 LeadTools dll,并将我的 unt 测试项目输出目录指向同一目录(让所有 LeadTools 二进制文件都在我的输出旁边)。但运行单元测试我得到以下执行:

测试方法 LeadTools.Evaluation.UnitTests.Snippets.PdfToTiffTest.PdfToTiffTest 抛出异常:Leadtools.RasterException:光栅 PDF 引擎是 需要使用此功能

我怀疑问题是由于 VSTest 进程在 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' 之外运行并且找不到必要的 LeadTools 二进制文件引起的。

问题:将 LeadTools 二进制文件引用到测试项目的正确方法是什么?

单元测试代码:

using System.IO;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Pdf;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace LeadTools.Evaluation.UnitTests.Snippets
{
    [TestClass]
    public class PdfToTiffTest
    {
        [TestMethod]
        public void PdfToTiffTest()
        {
            const string pdfPath = "C:\Samples\source.pdf";
            var tiffPath = Path.ChangeExtension(pdfPath, "tiff");

            // Load the input PDF document
            var document = new PDFDocument(pdfPath);
            using (var codecs = new RasterCodecs())
            {
                // Loop through all the pages in the document
                for (var page = 1; page <= document.Pages.Count; page++)
                {
                    // Render the page into a raster image
                    using (var image = document.GetPageImage(codecs, page))
                    {
                        // Append to (or create if it does not exist) a TIFF file
                        codecs.Save(image, tiffPath, RasterImageFormat.TifJpeg, 24, 1, 1, -1, CodecsSavePageMode.Append);
                    }
                }
            }
        }
    }
}

【问题讨论】:

    标签: unit-testing visual-studio-2012 file-conversion leadtools-sdk


    【解决方案1】:

    在 VS 2010 中,可以直接在测试设置中指定解决组件的位置。要在 VS 2012 中执行此操作,您可以在 App.config 中执行此操作,如 Visual Studio 测试团队的这篇文章 Assembly Resolution for Unit Tests 中所述。

    只需将 app.config 添加到您的测试项目中,并在其中放置适当的 AssemblyResolution> 详细信息。

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="TestExecution" type="Microsoft.VisualStudio.TestTools.Execution.TestExecutionSection, Microsoft.VisualStudio.QualityTools.ExecutionCommon, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </configSections>
      <TestExecution xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
        <AssemblyResolution>
          <RuntimeResolution>
            <Directory path="%ProgramFiles%\SampleApplication\" includeSubDirectories="true"/>
          </RuntimeResolution>
        </AssemblyResolution>
      </TestExecution>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-07
      • 2014-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多