I'm trying to set up a test environment using VS2015. The test project and the project to be tested both reside in the same solution and I've added a reference to the project to be tested. The code to be tested is configured as a DLL. In The object browser, things look like this, which seems to suggest that my test subjects are available to the UnitTest1 project:
Still, when I actually try to use build a simple test case I get unresolved exteral UnitTest1 symbol[...].
The actual test code is:
TEST_METHOD(TestMethod1)
{
int value = 2;
Testee t;
t.set_attribute(value);
//TODO add actual assertions
}
We've upgraded a VS2008 solution to VS2010 and then to VS2013 Pro. In VS2013 it all builds, but the unit tests all fail with the same error:
The unit test adapter failed to connect to the data source or read the
data.
The folder structure has not changed, and the test data files are all there in the correct location.
Here's a typical test:
[DeploymentItem(#"Autoscribe.Utility.Test\TestData\GetParameters1_RetrievesCorrectParameters.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", #"|DataDirectory|\Autoscribe.Utility.Test\TestData\GetParameters1_RetrievesCorrectParameters.xml", "test-record", DataAccessMethod.Sequential)]
[TestMethod(), Description("String extensions")]
public void GetParameters1_RetrievesCorrectParameters()
{
// Get test data.
string input = TestContext.DataRow["input"].ToString();
string[] outputs = TestContext.DataRow["outputs"].ToString().Split(new char[] { ',' }, StringSplitOptions.None);
// etc
}
In VS2008 there was a wizard to set the test properties to connect the test data file to the test, and using this often fixed this class of problem,but this doesn't seem available in VS2013 Pro. Can someone tell me:
a) how to connect a test to a data file in VS2013 Pro without having to explicitly type the DataSource attribute, and
b) any suggestions on how to fix this problem?
The trick was to explicitly select the original testrun config. It seems the upgrade does not carry this forward.
Earlier I was using gtest for my project. For the time being I am using gmock and when I have provided the path for gmock.lib, gmock_mock.lib and ..\..\include too. Then the control is not at all going into the code.
Suppose previously it was like e.g.
main()
{
printf("Hello world"); //Kept the breakpoint here, control comes here
}
Now after adding .lib and include paths it is not at all executing just strats debug and ends without going anywhere...
Please help me.
Google test lets you write unit tests using the TEST macro. It is not intended for use with normal programs that already have a main(). If you want to use google test you should create another project.
I have a Visual Studio 2010 solution with several projects, including .NET4 test projects. One such project, when I try to run it without debugging (Ctrl+F5), reports:
"Cannot start test project MyTestProject because the project does not contain any tests."
But, the project has several tests. Each test class is marked with the [TestClass] attribute, and each test method within is marked with the [TestMethod] attribute. Just to demonstrate my own sanity, I added this file and it still wouldn't recognize that there are tests.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Foo {
[TestClass]
public class UnitTest1 {
[TestMethod]
public void TestMethod1() {
}
}
}
The project is properly set as a test C# project. The tests in question also fail to show up in the Test List Editor's "Tests not in a list" section. (I translated most of the tests from VB.)
Why isn't Visual Studio recognizing the tests? How could I troubleshoot it?
Turns out that these tests were translated to C# from VB; when I translated them, I forgot to add explicit namespaces on them. Thus there were two test classes in the global namespace with the same name, which caused one to effectively replace the other. I just wish the warning given was a little less cryptic!
I'm using VS 2010 Professional (On Windows 7 Professional 64), writing with WCF 4.0.
I have the following code:
if (responseMessage.StatusCode == HttpStatusCode.NotFound)
{
throw new ContentNotFoundException(contentId, SSPErrorCode.PartnerRestGetStream404);
}
When attaching the debugger to the process, having set a breakpoint at the "if" statement or before that, while the condition is false (responseMessage.StatusCode is 'OK'), the debugger steps into the "if" statement. It then steps over the "throw" statement without doing anything, then continuing on with the code.
I've tried:
Restarting VS, logging out my Windows user, rebooting, cleaning the solution, building it again, rebuilding it, recycling the application pool, resarting IIS, adding more code inside the "if" statement and inside the condition - nothing worked so far.
There must be a cache somewhere which I can clean to get rid of it, but what, and where?
Googling this I only found http:--social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/d4b70fd7-b74a-42ce-a538-7185df3d3254/, so I tried manually setting the breakpoint, and it didn't break in this class, although the same did break in other classes.
I would love to fix this without reinstalling VS. Thank you in advance!
Update:
Since I put this up and could not find an answer, I moved on with my project.
I stumbled upon this issue, reported by John MacIntyre on this post, which ends up with a simplified example:
using System;
namespace IEnumerableBug2
{
class Program
{
static void Main(string[] args)
{
if (new object() == null)
throw new Exception();
try { } catch { }
}
}
}
Update #2:
Note that my Method also has a try-catch statement in it, a few lines after the 'if' statement.
I've just tried reproducing this bug again, and failed. I'm going to leave the question on stackoverflow for others who might need it, but, as I wrote, I am no longer able to reproduce the behaviour.
I am experiencing this problem too, but slightly different.
Here's my code:
string lockCode = Guid.NewGuid().ToString();
bool alreadyLocked = string.IsNullOrWhiteSpace(lockCode);
if (alreadyLocked) {
throw new Exception("already running");
}
try {
PerformTask(task);
}
finally {
UnlockTask(task, lockCode);
}
As you can see, the lockCode string is always assigned with a Guid value. The debugger steps into the 'if' scope, although it shouldn't. The exception isn't thrown.
I am running Visual Studio 2010 SP1 on Windows 7 64-bit with ReSharper 6.0.
Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.0.30319 SP1Rel
Installed Version: Premium
This happens to me with an ASP.NET application on framework 4.0.
I tried running the repro code posted here on a different project on my machine but could not reproduce the issue.
Also, I have deleted the Shadow Copy Cache for the .NET Framework on this path:
C:\Users\username\AppData\Local\assembly
I deleted the VS2010 symbols cache directory, and the Temporary ASP.NET Files.
I restarted my computer, cleaned the whole solution and rebuilt everything.
No clue why this happens.
Workaround: If I remove the 'try-finally' part from the method, or extract the throw statement to a different method, the debugger steps over the 'if' scope correctly.
Sorry for not posting a real solution to this, I hope this helps either isolate the problem or work around it.
Today I also experienced this issue. The following code solves the problem, with the advantage of not compiling the workaround on release builds:
using System;
namespace IEnumerableBug2
{
class Program
{
static void Main(string[] args)
{
if (new object() == null)
throw new Exception();
#if DEBUG
bool workaround = true; // dummy instruction
#endif
try { } catch { }
}
}
}
While stranger things have in fact happened, I highly doubt that this is a bug in the debugger or bad bad VS installation.
I think something must be happening that you're not interperting correctly. Did you put the expression "responseMessage.StatusCode == HttpStatusCode.NotFound" into the Debug Watch window? What does it return? Is it possible StatusCode is returning a different value each time? Did you try evaluating it several times to make sure it is consistent?
The only way I could imagine this happening is if the code was changed, and when prompted whether or not you want to debug the source file even though its version does not match, you answered Yes. This would explain why you can skip over the "throw" line without it doing anything - you're not debugging the actual code you're seeing, but an older version of it. To fix this, rebuild everything, and never say yes when prompted if you want to debug even though there is a version mismatch - it is way too confusing!