Evaluating Document Imaging SDK, I'm trying to create a unit test project in my Visual Studio 2012 to check some code snippets. I have referenced LeadTools dlls from installation directory 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' and pointed my unt test project output directory to the same directory (to have all LeadTools binaries next to my output). But running the unit test I'm getting the following execption:
Test method
LeadTools.Evaluation.UnitTests.Snippets.PdfToTiffTest.PdfToTiffTest
threw exception: Leadtools.RasterException: Raster PDF Engine is
needed to use this feature
I suspect that problem is caused by VSTest process is running outside the 'C:\LEADTOOLS 18\Bin\Dotnet4\Win32' and can' find necessary LeadTools binaries.
Question: What is the correct way of refencing LeadTools binaries to the test project?
Unit test code:
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);
}
}
}
}
}
}
In VS 2010 that was possible to specify where to resolve assemplies right in Test Settings. To do that in VS 2012, you could do that in App.config as described in this post Assembly Resolution for Unit Tests by Visual Studio Test Team.
Just add app.config to your test project and put there the appropriate <AssemblyResolution> details.
<?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>
Related
I've created a .NET Core 6 Web API project in Visual Studio for Mac. I can run the web API without issues and can interact with it using Swagger. I'm now attempting to create a MSTest project and write unit tests. I've written one however when I attempt to run it, Visual Studio for Mac appears not to do anything like so:
Unit Test:
namespace Tests;
[TestClass]
public class UnitTest1
{
[TestMethod]
public void ExampleTest()
{
var text = "hello.";
var result = text.ToUpperInvariant();
Assert.AreEqual("HELLO.", result);
}
}
Any ideas on what I'm missing?
I have been trying to run the iOS unit test from command line. I am using Xamarin Studio on Mac for now, I Created a iOS Unit test project as follows
Add New Project --> iOS --> Tests --> Unit Test App
And added a simple Unit test class and its code snippets as shown below:
using System;
using NUnit.Framework;
namespace iOSUnitTest
{
[TestFixture]
public class iOSTestSample
{
public iOSTestSample()
{
}
[Test]
public void MySampleTest() {
Assert.True(true);
}
[Test]
public void MyFailerTest()
{
Assert.False(true);
}
}
}
From Xamarin Studio, I am able to run the application which deploys a app into simulator and execute the test cases. I am trying to automate it through a script.
Till now, I am able to get the Unit Test project build and install the app into the running simulator.
I am not sure how to automate the unit test execution once the app is installed.
This blog post (and the ones linked( might be a bit out-dated but it shows you how to automate unit testing (both simulator and device builds) with the tools that ships with Xamarin.iOS.
I wrote a simple Class Library with a method GetNodes to examine content of the chosen directory.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public void GetNodes(string directoryPath)
{
if (directoryPath == null)
throw new ArgumentNullException("directoryPath");
//Remove white-space characters from the start and end of path.
directoryPath = directoryPath.Trim();
bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
(...)
}
project.json:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.3.0"
},
"frameworks": {
"netstandard1.3": {
"imports": "dnxcore50"
}
}
}
Project has been built successfully.
Then in order to perform some unit tests I created a simple Unit Test project (.Net Framework 4.6)
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void DetectException_WhenCorrectExceptionIsThrown()
{
FileManager fm = new FileManager();
fm.GetNodes(#"c:\");
}
Every time I run the test I get this error:
Test Name: DetectException_WhenCorrectExceptionIsThrown
Test FullName: Task_2_Test.FileManagerTests.DetectException_WhenCorrectExceptionIsThrown
Test Source: D:\Git\task_2\Task_2\test\Task_2_Test\FileManagerTests.cs : line 25
Test Outcome: Failed
Test Duration: 0:00:00,0152049
Result StackTrace:
at Task_2.FileManager.GetNodes(String directoryPath)
at Task_2_Test.FileManagerTests.DetectException_WhenCorrectExceptionIsThrown() in D:\Git\task_2\Task_2\test\Task_2_Test\FileManagerTests.cs:line 30
Result Message:
Test method Task_2_Test.FileManagerTests.DetectException_WhenCorrectExceptionIsThrown threw exception System.IO.FileNotFoundException, but exception System.ArgumentNullException was expected. Exception message: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Nie można odnaleźć określonego pliku.=== Pre-bind state information ===
LOG: DisplayName = System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///D:/Git/task_2/Task_2/test/Task_2_Test/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : Task_2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\VISUAL STUDIO EXPRESS 2015\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///D:/Git/task_2/Task_2/test/Task_2_Test/bin/Debug/System.Runtime.InteropServices.RuntimeInformation.DLL.
LOG: Attempting download of new URL file:///D:/Git/task_2/Task_2/test/Task_2_Test/bin/Debug/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.DLL.
LOG: Attempting download of new URL file:///D:/Git/task_2/Task_2/test/Task_2_Test/bin/Debug/System.Runtime.InteropServices.RuntimeInformation.EXE.
LOG: Attempting download of new URL file:///D:/Git/task_2/Task_2/test/Task_2_Test/bin/Debug/System.Runtime.InteropServices.RuntimeInformation/System.Runtime.InteropServices.RuntimeInformation.EXE.
I see that this error is connected with System.Runtime.InteropServices (I use this library to check the current OS in order to verify correct syntax of the directory path).
I don’t want to resign from this feature, but I have no idea how to deal with this.
Btw. My Ide is Visual Studio Community 2015.
Thank you in advance for your support.
you may use xunit for as your unit test framework.
I had issues with adding xunit via vs2015 update 3 too, i published my work around on http://jickingnotes.blogspot.com/2016/10/add-xunit-test-project-in-net-core.html
in my case I spotted the reason was update to 2017, and a lot not needed properties in PropertyGroup of csproj. Like RuntimeFrameworkVersion, NetStandardImplitPackageVersion
In short, using a .runsetting unit test file in a build step on TFS 2015 results in a 503 Service Unavailable exception.
After extensive searching and testing on a new TFS 2015 installation (as also described in TFS2015 new install, 503 Service Unavailable), I may have found the problem.
We are using .runsettings files as described on https://msdn.microsoft.com/en-us/library/jj159530.aspx, in a 'Visual Studio Test' build step on our new TFS2015 installation, as soon as the VSTest.console.exe is called, the next three application pools on the TFS server crash, resulting in a 503 Service Unavailable error:
DefaultAppPool
Microsoft Team Foundation Server Application Pool
Microsoft Team Foundation SErver Message Queueu Application Pool
First my .runsetting file was kind of large, but i did try the next one (I think as small as possible):
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations for data collectors -->
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<!-- Match assembly file paths: -->
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
<ModulePath>.*fluentassertions.*</ModulePath>
<ModulePath>.*\.test\.dll$</ModulePath>
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
When using this one, the app pools crashes. Even if i remove the part entirely, it will not work.
As soon as the next line is called (taken from the log lines of the build step), the app pools crashes.
Executing C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "D:\TfsAgents\Agent1\_work\2\s\[...]\Release\Microsoft.QualityTools.Testing.Fakes.dll" "D:\TfsAgents\Agent1\_work\2\s\[...]\Release\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll" "D:\TfsAgents\Agent1\_work\2\s\[...]\Release\MyClassLib.dll" /Settings:"D:\TfsAgents\Agent1\_work\2\s\[...]\test.runsettings" /EnableCodeCoverage /logger:trx
If you look at the DataCollector tag in the .runsettings file, you see the version is set to 14.0.0.0. If you look at the page of Miscrosoft, they state that it should be 11.0.0.0, but also this version does not work. I thought it might be that version 11.0.0.0 was wrong, so I opened the dll with Telerik JustDecompile, and saw that the 'real' version was 14.0.0.0, so I put that version into the runsetting-file. But no luck.
So for now I'm just remove the runsetting file from the definition of the build, which unfortunately results in a wrong code coverate percentage.. So hopefully someone might have the answer for this.
This problem is limited to the specific runsettings file when used with build agent running on the same machine where IIS server is hosting TFS. There is a workaround available. Within DataCollectors->Configuration->CodeCoverage tag in runsettings file you can add following xml tags with given values :
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>false</CollectAspDotNet>
This should solve the issue, and also its recommended that in future if you are using runsettings file with Code coverage in Data Collector then these tags should be added.
I am not a C programmer, but i have to run boost tests on my Jenkins. Now I have installed the xUnit plugin in Jenkins.
I added a post-build action : "Publish xUnit test result report"
Then, in this post-build step I added : "BoostTest-1.x (default)"
Now I have the following options to set:
https://www.dropbox.com/s/wxcny55rz2bqk6r/boost_jenkins_options.png
The options I set are random, so please help me, I don't understand anything and I didn't find some tutorials.
I have not worked with boost unit test and not with the xUnit Jenkins plugin either.
Can any one help me?
edit: jenkins say me this:
make[1]: Leaving directory `/var/lib/jenkins/workspace/southernd_test'
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing BoostTest-1.x (default)
[xUnit] [INFO] - [BoostTest-1.x (default)] - No test report file(s) were found with the pattern 'boost/*.xsl' relative to '/var/lib/jenkins/workspace/southernd_test' for the testing framework 'BoostTest-1.x (default)'. Did you enter a pattern relative to the correct directory? Did you generate the result report(s) for 'BoostTest-1.x (default)'?
[xUnit] [ERROR] - No test reports found for the metric 'BoostTest' with the resolved pattern 'boost/*.xsl'. Configuration error?.
[xUnit] [INFO] - Setting the build status to FAILURE
[xUnit] [INFO] - Stopping recording.
Build step 'Publish xUnit test result report' changed build result to FAILURE
Finished: FAILURE
The error is is because there is no output file generated by boost::test. The test script need to be invoked with the correct options:
unit_test --report_level=detailed --report_format=xml 2> xunit.xml
Unfortunately the XML output file produced by boost::test is not in the correct format
(see: SO Converting boost::test logs & Boost Users Help with XUnit plugin )
The JUnit plugin expects XML test output to be in the following format:
<testsuites>
<testsuite time="0.0000" timestamp="0.000" errors="0" failures="0" tests="13" hostname="localhost" name="my_test_suite">
<testcase id="65536" class="test" name="test_case_1" time="0.0000" />
<testcase id="65537" class="test" name="test_case_2" time="0.0000" />
<testcase id="65538" class="test" name="test_case_3" time="0.0000" />
</testsuite>
</testsuites>
There are a couple of ways to resolve this such as:
Converting the XML output by boost::test
Directly customising the output of boost::test so that the correct format is produced.
I opted for option 2 - ss you are not a 'C/C++' programmer you could get the author of the test suites you are trying to run to follow this approach, the steps below should help get them started:
Create a test visitor for post processing the results of the test run.
Create a BOOST_GLOBAL_FIXTURE class that walks through the test results in its destructor to output the test results in the correct format.
Instantiate the fixture class in the main test module.
i.e.:
struct JUnitVisitor : public boost::unit_test::test_tree_visitor
{
void visit( boost::unit_test::test_case const& tc )
{
// output <testcase> xml in JUnit format
}
bool test_suite_start( boost::unit_test::test_suite const& ts )
{
// output <testuite> xml in JUnit format
}
void test_suite_finish( boost::unit_test::test_suite const& ts )
{
// output </testuite> xml in JUnit format
}
};
struct MyJUnitOpFixture
{
MyJUnitOpFixture() {}
~MyJUnitOpFixture()
{
// open results file
/// output <testsuites> start tag
// use a visitor to walk the test results tree
JUnitVisitor visitor ( out );
boost::unit_test::traverse_test_tree(
boost::unit_test::framework::master_test_suite(),
visitor
);
/// output </testsuites> end tag
}
}
Then the global fixture is instantiated in the main test file by adding:
BOOST_GLOBAL_FIXTURE( MyJUnitOpFixture );
In my case xUnit does not like format of Boost Test's "--report_format=XML" but it DOES take "--log_format=XML --log_sink=test.xml"