I suspect this problem might be due to a bad configuration. The simplest unit test hangs also. Basically, whatever I put in my unit test does nothing, the test is launched and keeps loading until it reaches timeout. My initial test used a TransactionScope, DataContext and custom objects. I then simplified my unit test to the following, and it still hangs:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ManifestService;
using System.Transactions;
namespace UnitTesting
{
[TestClass]
public class PackagerUnitTest
{
[TestMethod]
public void Packager_CreatePackageType()
{
string expected = "test-package";
Assert.AreEqual("test-package", expected);
}
}
}
So, it was a configuration issue, at the visual studio level. Basically, you need Visual Studio 2010 SP1 if you want to run unit tests while having Visual Studio 2012 installed at the same time.
Thanks for the answer from this blog:
http://dorkasaurusrex.blogspot.ca/2012/11/visual-studio-2010-unit-test-hangs.html
SP1 download link:
http://www.microsoft.com/en-us/download/details.aspx?id=23691
Related
I was recently watching tutorials on C# where they mentioned that specifying either using System and then using Console.WriteLine or writing System.Console.WriteLine if you don't specify using <namespace> was necessary for proper namespace resolution to happen when writing programs otherwise the compilation would fail.
But when I'm using Visual Studio 2022, Console.WriteLine seems to work without specifying any namespace at all.
Is this some optimisation that Visual Studio 2022 does? Why is this working?
On top of this, if I use System.Console.WriteLine, VS 2022 also greys out System and says "name can be simplified".
Try this
using System;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
If you create c# project of asp.netframrwork. It will automatically generate the "using System" namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
}
}
}
If your console project is .NET 6 and above. Please refer to Exploring Ideas to Build Code While Learning Using Top-Level Statements.
Hope it helps you.
I recently started working with Visual Studio 2017. Jumping from 2010.
I created a new, very basic, console application and I am trying to test. The code runs fine but I am not seeing a console dialog anywhere (I have breakpoints and also a Console.Read()). I checked 'behind' all the windows. See nothing in the task tray.
Any ideas? Any new settings that I am not aware of?
Here is all of the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleTest2
{
class Program
{
static void Main(string[] args)
{
Console.Read();
}
}
}
Definitely a console application.
Project Info
I'am totally new to Windows Store App programming,
so i'am also new to Visual Studio Express.
My goal is to test a simpple class method.
As mentioned here the Express version do not have any built-in Unit testing.
In this thread, Rafal provides a solution.
I exactly did it like described, so my external tools look like this:
When i execute it (Tools --> "Execute NUnit"), Nunit starts and the Gui of NUnit appears. But suddenly this exception occurs:
And in Exception Details:
System.IO.FileNotFoundException...
at NUnit.Util.ProjectService.WrapAssembly(String assemblyPath)
at NUnit.Util.ProjectService.ConvertFrom(String path)
at NUnit.Util.ProjectService.LoadProject(String path)
at NUnit.Util.TestLoader.LoadProject(String filePath, String configName)
My project folder has this structure:
The test classes are in "WebTest.Shared".
I think i need a .dll to run in NUnit as mentioned by Jon here.
So, how can I make a dll out of my project to run it with NUnit?
Can anyone guide me through this problem? (Please step by step)
EDIT:
After i worked in ChrisM idea, the exception stll arises without "${BinDir}${TargetName}.dll/run" block (the exception details are the same as before):
EDIT No. 2:
I have set those values:
Title: Execute NUnit
Command: D:\Path\To\NUnit\bin\nunit.exe
Arguments: $(BinDir)$(TargetDir)$(TargetExt)/run
Initial directory: $(BinDir)
EDIT No. 3:
After closing and reopening VS Express
i got this new Exception:
And in NUnit Exception Details:
System.ApplicationException: Unable to find test in assembly
System.ApplicationException...
EDIT No. 4
Here is my test class (StringUtilitiesTest.cs):
using System;
using System.Collections.Generic;
using System.Text;
using WebappTest.Shared.Utilities;
using NUnit.Framework;
namespace WebappTest.UnitTest
{
[TestFixture]
public class StringUtilitiesTest
{
[Test]
public void TransferFunds()
{
Assert.AreEqual("Hello", StringUtilites.getString("Hello"));
}
}
}
In external Tools:
Have you tried replacing the curly braces {} in the argument box with normal ones ()?
Visual Studio 2017 Express (the final express version) includes the test explorer. Add the NUnit3TestAdapter NuGet to your project, and the test explorer should discover your tests.
I want to use Appium to make automated testing for my Android app. I downloaded the Appium for Windows and could run my app on device from within appium.exe. Now I want to write test cases in C# which make use of selendroid integrated in Appium. I googled a lot but couldn't find any example demonstrating the same. I found one project on github but it's giving a lot of compiler errors. Could anybody guide me about how to write test cases using Appium in C#? If you have any resources, please provide me the same. Thanks.
You can go with installing Visual Studio 2012 or visual express for web. Use NUnit framework to write the test cases and execute them as a class library project in that.
1) Create a class library project and create a new class e.g "Class1". Add the packages as provided in the links above. Try the below code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using OpenQA.Selenium.Interactions;
using System.Threading;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Appium.Interfaces;
using System.Drawing;
namespace ClassLibrary2
{
[TestFixture]
public class Class1
{
public AppiumDriver driver;
public DesiredCapabilities capabilities;
public Class1()
{
Console.WriteLine("Connecting to Appium server");
capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "Android");
capabilities.SetCapability(CapabilityType.Platform, "Windows");
capabilities.SetCapability(CapabilityType.Version ,"4.1.2");
capabilities.SetCapability("Device", "Android");
//Application path and configurations
driver = new AppiumDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
}
[Test]
public void login()
{
driver.FindElement(By.Name("Country")).Click();
//Your further code as per the application.
}
Then Build a solution for your project and run it in NUnit.
I've tried unit testing within VS2012 for the first time and I'm using VS2012 update 4. When I click "Run All" in the Test Explorer window, it takes about 5 to 10 seconds for the tests to start running. I foud this: Visual studio 2012 slow unit testing but it didn't fix it. Other fixes I've read suggest getting the newest version of VS2012 but I believe I have that. Anything else I could try?
Edit: I also tried uninstalling VS 2010 as I read that might be a cause.
Side question: Is there a way to stop VS from returning to the output window every time I click "Run All" for tests? This is just weird. I of course want to see the test results so I want to remain on the Test Explorer window.
Code just in case:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using MyProject;
namespace MyProjectTest
{
[TestClass]
public class FooTest
{
private Bar _bar;
[TestInitialize]
public void TestInitialize()
{
}
[TestCleanup]
public void TestCleanup()
{
}
[TestMethod]
public void Baz_AllLefts_5()
{
Assert.IsTrue(true);
}
}
}