I am using Visual Studio 2015 IntelliTest to do the data driven test execution which is very useful tool for data driven testing. Visual Studio 2015 Intelli test is getting failed when I am running the intellitest from a project created by intellitest. But the same is passing when running the test from a test explorer window. We have implemented repository pattern and using Entity Framework 6.0 to carry out the database operations. Please find the stack trace below for more information. Can anyone help me on this?
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Void MyFramework.Persistence.Entity.EF1Repository..ctor(System.String connectionStringName, System.String objContextName)
at System.Void MyFramework.Persistence.PersistenceManager..ctor(System.String schema, System.String module)
at System.Collections.Generic.List`1<MyDTO> BusinessLogic.ListedPassenger.Passengers(MyDTO entity)
at System.Collections.Generic.List`1<MyDTO> BusinessLogic.Tests.ListedPassengerTest.PassengersTest(BusinessLogic.ListedPassenger target, MyDTO entity)
Please ensure that your test is isolated from the environment using appropriate mock implementations (using Fakes, etc.). Take a look here for a hands-on example: https://blogs.msdn.microsoft.com/visualstudioalm/2015/08/14/intellitest-hands-on/.
Related
I am merely a beginner and still trying to learn about TFS and its continuous integration workflow. Having that said, this could as well be a stupid question to ask as I might be missing on a simple detail, though any help or advice would be highly appreciated.
So, I have a fairly simple Unit Test example written using .NET Core 2.0, which I would like to run as a test task on our TFS Server's CI Build pipeline. It pretty much looks something like this:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MyUnitTest
{
[TestClass]
public class MyUnitTest
{
[TestMethod]
public void PassingTest()
{
Assert.AreEqual(4, Add(2, 2));
}
[TestMethod]
public void FailingTest()
{
Assert.AreEqual(5, Add(2, 2));
}
int Add(int x, int y)
{
return x + y;
}
}
}
When I try to run these tests in Visual Studio, it builds perfectly and the tests succeed and fail accordingly. So I commit my project and push it to our TFS git repository. Now, I similarly would like to integrate these tests in our build pipeline.
The Build Definition used in our CI builds looks like this. I have added Visual Studio Test - testAssemblies task in the build pipeline and configured the search pattern to find the assembly named MyUnitTest.dll and such. When I queue the build, I get the following warning in VSTest's log.
Warning: No test is available in C:\BuildAgent\_work\9\s\MyUnitTest\MyUnitTest\bin\release\netcoreapp1.1\MyUnitTest.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
So, it seems to me that VSTest somehow cannot find tests to run in the target assembly. I am pretty positive that I might have misconfigured something, or forgotten to set some particular parameter appropriately. I will be more than grateful for any suggestion that would possibly pinpoint what I might be doing wrong.
Searching for solutions online, I have come across this question, which seems to have a similar problem.
First make sure your build agent environment is as same as your local develop machine. Such as Visual Studio version, MsTestAdapter ,xunit runner version and so on.
You could double confirm this by manually run the test directly on the build agent machine not through TFS.
Then use the below tasks in your build pipeline:
Add a dotnet restore task.
Then a dotnet build task.
Add a dotnet test task with the arguments --no-build --logger "trx;LogFileName=tests-log.trx
Add a Publish test results task with the following settings
More details please refer this tutorial blog: Running dotnet core xUnit tests on Visual Studio Team Services (VSTS)
I am getting the following exception from NCrunch when tests are being run.
*** Failures ***
Execute
TypeMock.TypeMockException:
*** Typemock Isolator is currently disabled. Enable using the following:
* Within Visual Studio:
- Use Typemock Smart Runner
- For other runners, Choose Typemock Menu and click "Integrate with Other Runners"
* To run Typemock Isolator as part of an automated process you can:
- run tests via TMockRunner.exe command line tool
- use 'TypeMockStart' tasks for MSBuild or NAnt
For more information consult the documentation (see 'Running Unit Tests in an Automated Build')
HResult: -2146233088
at TypeMock.InterceptorsWrapper.VerifyInterceptorsIsLoaded()
at _I2KaEbJqCiZdAXHCaew5L4YgGK2_._YVpKHl6s8x54awChyHFFGG1W9p_._M9wuZsfNQUSOigKL83XBnloMATg_()
at TypeMock.MockManager.Init(Boolean collectAllCalls)
at _gpWkmvHy51MsHfP5XcTmisQFOGh_._w05d89eUlRCsAnXfWIN6HIvOW7P_._LZu54JRvjOVy0mycnVTOacyFHBR_[?](Members , Constructor , Constructor , Type , Object[] )
at _gpWkmvHy51MsHfP5XcTmisQFOGh_._w05d89eUlRCsAnXfWIN6HIvOW7P_.Instance[T](Members behavior, ConstructorWillBe constructorBehavior, BaseConstructorWillBe baseConstructorBehavior)
at NOES.Business.Control.Rollformers.RollformerStateIdleTest.SendNextBagTest() in C:\Users\Frank Adcock\Documents\noes_3\src\NOESTest\Business\Control\Rollformers\RollformerStateIdleTest.cs:line 18
Version Details
VS2015 14.0.25420.01 Update 3
Typemock 8.5.0.2
Test Frameworks Galio/MbUnit or Nunit 3.43
From what I can read of the documentation Typemock is supposed to be automatically picked up by NCrunch, but this does not appear to be happening.
Any assistance welcomed
We fixed this issue and you gonna see it in our next release.
As a workaround for now:
Find a "knownRunners.dat" in the Typemock Examples folder
Add 2 lines to it: "nCrunch.EngineHost462.x64", "nCrunch.EngineHost462.x86"
See here a full info
Tell me if it helps.
Disclaimer, I work in Typemock.
First of all, have you enabled "Integrate with Other Runners" in Typemock VS menu and "Enable Mocking integration" and "Enable Auto Linking" in Typemock->Options->Mocking Integration?
Which version of NCrunch you use?
I'm currently in the process of increasing code coverage on our software products and have ran into an issue; all of my unit tests (when compiled using 'Any CPU') are failing due to throwing a 'BadImageFormatException'.
This exception can be circumvented by building the solution using 'x86' instead of 'Any CPU', however the requirements are such that we need to be able to run them using Any CPU/x64 bit.
All unit tests involving Moq follow pretty much the same format:
[TestMethod]
public void GetProduct_ValidId_ProductReturned()
{
//Setting up the object
Product prod = new Product();
prod.ID = 7;
prod.Name = "Test";
//Create the mocks
var mockProductRepo = new Mock<IRepository<Product>>();
var testDb = new Mock<IUnitOfWork>();
//Setup what the repo needs to return, in this case it's a Product
mockProductRepo.Setup(m => m.getByID(7)).Returns(prod);
//Setup what the database needs to return, in this case it's our repo which we've already setup
testDb.SetupGet(m => m.ProductRepo).Returns(mockProductRepo.Object);
//Run the test
Product returnedProd = ProductHelper.getProduct(testDb.Object, 7);
Assert.IsNotNull(returnedProd);
}
I can confirm that this test is successful when it is built using x86. Does anyone have any ideas on how I can get Moq to play nice when built using 'Any CPU'?
As an aside I can also confirm that all my projects in the solution are build using the same value ('Any CPU'). I'm using Moq v4.0.
EDIT: Here is the full exception: Test method [ProductName and the method called] threw exception:
System.BadImageFormatException: Could not load file or assembly '[Product name], Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Ok so after some digging I finally found out what the issue was. Even if you select 'Build' and then 'Configuration Manager' from the toolbar and see that Platform is set to 'Any CPU' (as was my case), what I hadn't done was check the Target Platform in the project.
To check the Target Platform you need to do the following:
Right-click your project and select 'Properties'
Select the 'Build' tab on the left
Ensure that the Target Platform of your test project matches that of the project you are testing
In my case my test was targeting 'Any CPU' but my live project was targeting 'x64'. This is what was causing the issue.
This can be caused by missing project or other assembly references. Try making sure you have project references for all the projects in your solution.
This post has a further example.
I am developing a Wp7-App and I want to start Unit Testing. I used the Template from Visual Studio 2010 to create a Windows Phone 7.1 UnitTest-Project and I added the required Assemblies via Nu-Manager.
I can't start the project in emulator or on a real device. I get a blank loading-screen and this error message:
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
Is this a known error? Is there a workaround?
Thanks!
The standard VS Unit test template won't work for WP7. You should look at these links:
http://channel9.msdn.com/Events/MIX/MIX10/CL59
and
http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/
I have a Silverlight 4 Test Project using the Jeff Wilcox assemblies and it works fine for my WP7 tests. I use [TestClass] and [TestMethod] attributes and these namespaces inside my tests:
using Microsoft.Silverlight.Testing; using
Microsoft.VisualStudio.TestTools.UnitTesting;
Within the App.xaml.cs file there is minimal code and the following starts it all off:
private void Application_Startup(object sender, StartupEventArgs e)
{
RootVisual = UnitTestSystem.CreateTestPage();
}
In my project I write tests using Microsoft's unit testing framework. All of my tests pass when I run them from Visual Studio but when I run the tests from MSBuild all of the tests fail with the following erorr message:
Unit Test Adapter threw exception:
Type is not resolved for member
SomeType,SomeAssembly Version=assemblyVersion,
Culture=neutral, PublicKeyToken=..
The assembly not found is a 3rd party assembly referenced by all of the projects.
The build script is used by TFS so I've aded the following lines:
<RunTest>true</RunTest>
<ItemGroup>
<MetaDataFile Include="$(BuildProjectFolderPath)myproject.vsmdi">
<TestList>CI_Tests</TestList>
</MetaDataFile>
</ItemGroup>
I've found the this post that shows a solution to this issue but unfortunatly I cannot chnage the files on the TFS server.
Help!
I encountered the same problem in my unit tests. The linked article above indicates that the problem is that VSTS causes copying of some objects in the thread's CallContext.
For what it's worth, in my case the problem was that I had manually placed an object in the thread's CallContext, which caused this exception. I was able to resolve this by clearing the CallContext in my TestCleanup routine. I didn't have to change any files anywhere.
I had also run into the same issue but where I had StructureMap initialisation being performed within the constructor for a base test class.
I was able to get around the problem by moving the call from the constructor to the [TestInitialize] method. I also ensured that the [TestCleanUp] method disposed of the created StructureMap container. After this MSBuild (2010) would run through the tests without raising this error.
The first thing to check would be if this assembly is copied to the folder from which msbuild runs the tests. It might be the case that you have a copy in your bin/Debug folder because of some historic reasons, but the dependency is not set up properly in the project.
Had this error
Unit Test Adapter threw exception:
Type is not resolved for member 'NHibernate.HibernateException,NHibernate
As it turned out the problem was in exception thrown in static constructor for the test.
It was completely unrelated to the looks of message and was happening during DB creation using BuildSchema.
Very uninformative error message by MSTest which cost me a lot of hours and stress. putting migration to something better like NUnit in our TODO list.
This article solved my problem with this error:
To recap, MyCustomException was thrown at very early stage of test execution. The dll that contained it was not loaded yet so Unit Test Adapter indeed could not reach it.
Happening when the assemblies been tested have loaded instances of their class marked as [Serializable]. Workaround by deriving from MarshalByRefObject so the deserialization is no longer attempted from mstest host.