I had a good time with Nunit 2.6 + ReSharper 7, but after I install Ncrunch, my Visual Studio 2010 just fell apart and I can't run Unit Tests inside the Unit Test Sessions.
Error Message:
The project xxxx has not been built
Typical setup would be
Project XXXX - No Main
Project XXXX.Test - Some Code
Some code in XXXX.Test
[TestFixture]
public class Entry
{
[Test]
public static void ThisWillPass()
{
Assert.AreEqual(1,2);
}
}
Note: I did set the Configuration Manager to "build" on the xxxx.test
Please advise.
Is your project set as AnyCPU? If not check the resharper settings for a setting that controls if the framework it uses running the tests is 32bit or 64bit and make sure it is set the same.
Related
I need to learn about how to set-up a winappdriver windows app test project in visual studio and inspecting the elements for a medium size windows application.
Navigate to the WinAppDriver GitHub web page and download the latest
version. I downloaded the 1.2 version
After installation, you will find the diver at C:\Program Files
(x86)\Windows Application Driver location.
First, we need to enable Developer Mode on our Windows 10, Developer
mode is not enabled. Enable it through Settings and restart Windows
Application Driver
If you have Microsoft Visual Studio installed, you will most likely
have Element Inspector already installed on your machine
In case you do not have it installed, navigate to the Windows 10 SDK
site, download and install it.Run the inspect.exe and make sure it is
working fine
**.
Create a new NUnit test project
2- download appium dependency from NuGet
3- Update an existing UnitTest1.cs class as follows:**
using NUnit.Framework;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System
[SetUp]
public void Setup()
{
AppiumOptions Options = new AppiumOptions();
Options.AddAdditionalCapability("app", "C:\\Windows\\System32\\notepad.exe");
Options.AddAdditionalCapability("deviceName", "WindowsPC");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), Options);
Assert.IsNotNull(DesktopSession);
}
[TearDown]
public void Close()
{
DesktopSession.CloseApp();
}
}
4= Run the test
Note: If some references or packages are missing, right-click on it and include it in the solution.
5- Create Windows Elements and perform actions
Open up application under test (AUT), in our case it is Notepad.exe, and Inspect.exe tool to fetch locators.
Click on the Notepad text area and find the AutomationId attribute on the right-hand side of the Inspect.exe tool.
WindowsElement NotepadTextArea = DesktopSession.FindElementByAccessibilityId(“15”);
NotepadTextArea.SendKeys(“Hello World”);
Try! try! ,Run the test! Run the test! Run the test!
#pawansinghncr's answer is correct, but I would also suggest trying out the UI Recorder, it's in the Releases page of the WinAppDriver's Github.
I'm pretty new to CI (from a brand new set up point at least). I created a project in Rider, using the default version of NUnit that is provided if you select to 'Create new NUnit Project', and I am now trying to set up an automated build for it using travis-CI.
The target .NET framework version of my project and test projects (confirmed in Project properties in Rider) is 4.5.
The version of Nunit I am using is the default version provided with Rider, 3.5.
Here is my .travis.yml build file:
language: csharp
solution: .sln
install:
- nuget restore FindWordsWithConcatenations.sln
- nuget install NUnit.Runners -Version 3.5.0 -OutputDirectory testrunner
script:
- xbuild /p:Configuration=Debug ./FindWordsWithConcatenations.sln
- mono ./testrunner/NUnit.ConsoleRunner.3.5.0/tools/nunit-agent.exe ./TestFindWordsWithConcatenations/bin/Debug/TestFindWordsWithConcatenations.dll
I confirmed on my own machine by running the nuget command that the test runner path should be correct, when I run the nunit-agent (via agent, agent-x86, or agent-console) I get the following error (locally, and on the server):
Unhandled Exception: System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
at System.Guid..ctor(String g)
at NUnit.Agent.NUnitTestAgent.Main(String[] args)
I've also tried running with no configuration mode specified, and with configuration mode of Debug and Release specified.
Unfortunately, the normal tactic of googling/stack overflow hasn't helped, I've seen this error in a few questions, but the cause never seems related to what I'm experiencing.
The last build of the pipeline is available to view here, all the builds thus far have failed, previous builds can be seen here.
Thanks in advance, I would be very grateful if someone had any idea about the cause of this issue, or how I could tackle the test running in a different way.
Solved it.
Updated the script section of the travis config to:
script:
- xbuild /p:Configuration=Debug ./FindWordsWithConcatenations.sln
- mono ./testrunner/NUnit.ConsoleRunner.3.5.0/tools/nunit3-console.exe ./TestFindWordsWithConcatenations/bin/Debug/TestFindWordsWithConcatenations.dll
So it's now running the correct console application. Also had to modify the test paths a bit for it to run on the server.
I wrote some tests and add solution that execute it smth like this:
class Program
{
static void Main(string[] args)
{
SmokeTests test = new SmokeTests();
test.Init();
test.OneCanLoginMail();
test.Cleanup();
}
}
And test example in another project,with Nunit and Selenium WebDriver libraries.
[Test]
public void OneCanLoginMail()
{
steps.LoginMail(USERNAME, PASSWORD);
Assert.True(steps.IsLoggedIn(USERNAME));
}
If i start up project via console everything ok and tests executed as expected.
Then i installed Jenkins,install MSBuild plugin, configured it and succesfully built project.
1>Done Building Project "C:\Users\Admin\Documents\Visual Studio 2015\Projects\QAlabs\test\StartUp\StartUp.csproj" (build target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
But tests are not running.What should i add to view assert log and execute tests?I think i need xml file somewhere smth like maven build file but for .Net
To run your NUnit tests, you have to execute nunit-console.exe after your MSBuild step.
Jenkins batch
NUnit 2.6.4 had a nunit-console-runner.dll file that I could use in my C# app as follows:
string[] my_args = { "/run=SmokeTests.ATest", "Tests.dll" };
NUnit.ConsoleRunner.Runner.Main(my_args);
But I don't see this dll in 3.0. Is there one? If not, how can i use the same command to run NUnit tests programmatically?
Nunit 3 Console Runner can be installed as a reference of the nuget package from - https://www.nuget.org/packages/NUnit.ConsoleRunner/
nunit3-console.exe file will be stored under Project Directory >> Package >> nunit-console runner folder
Further documentation can be found here - https://github.com/nunit/docs/wiki/Console-Runner
I'm currently working on a Windows Store Application (Windows 8) for a class and I'm having problems getting my NUnit tests to run.
My Solution/Project setup looks like the following:
TheMetroApp.sln
SQLite-net.csproj - Class Library (Windows Store Apps). Files are pulled from NuGet.
DataModel.csproj - Class Library (Windows Store Apps)
UnitTests.csproj - Unit Test Library (Windows Store Apps). NUnit framework is pulled from NuGet.
TheMetroApp.csproj - A project file which was pulled from one of the Windows SDK examples.
Misc. Dependencies and Utilities
Windows 8 Pro RTM/Visual Studio 2012 RTM
ReSharper 7
NUnit 2.6.1
SQLite (Set up per the instructions here)
UnitTests is dependent upon and references DataModel. DataModel is dependent upon and references SQLite-net. The only thing I have added to the UnitTests project is a single class containing some stub NUnit unit tests. As far as I can tell, these are set up correctly:
[TestFixture]
public class TaskSourceTests
{
#region Private Class Members
private ITaskSource _taskSource;
private String _dbPath;
#endregion
#region Testing Infrastructure
[SetUp]
public void SetUp()
{
// This part makes NUnit/ReSharper have problems.
_dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "UnitTestDatabase.sqlite");
}
#endregion
#region Misc. CRUD stuff
[Test]
public void CreateTaskTest()
{
// Save the task.
Task task = new Task( "Some Task", "lol.", DateTime.Now, false );
_taskSource.Save( task );
// Confirm that it is in the task db.
using( SQLiteConnection db = new SQLiteConnection( _dbPath ) )
{
const String query = "SELECT * FROM Task WHERE Id = ?";
IList<Task> results = db.Query<Task>( query, task.Id );
Assert.True( results.Contains( task ) );
}
}
// ...and so on [but with stubs that are basically Assert.Fail( "" )].
#endregion
}
TheMetroApp is one of the Windows 8 SDK sample projects, but with some custom XAML forms thrown in. I'm not having any problems with this project.
My issue is that none of the Unit Test runners that I have tried to use are working.
When I try to use the official NUnit x86 Test runner (version 2.6.1), my tests fail due to certificate related issues (see here):
UnitTests.TaskSourceTests.CreateTaskTest:
SetUp : System.InvalidOperationException : The process has no package identity. (Exception from HRESULT: 0x80073D54)
ReSharper's NUnit test runner fails for the exact same reason. Unfortunately, it doesn't look like there is currently a workaround for that.
I have also tried using the test runner built into Visual Studio 2012 (through the NUnit Visual Studio Test Adapter). When I try to run my tests using "Run All", I get the following output:
------ Run test started ------
Updating the layout...
Checking whether required frameworks are installed...
Registering the application to run from layout...
Deployment complete. Full package name: "GibberishAndStuff"
No test is available in C:\Projects\project-name\ProjectName\UnitTests\bin\Debug\UnitTests.dll. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
========== Run test finished: 0 run (0:00:09.4873768) ==========
Something strange I have noticed is that if I select a specific test in the Test Explorer and tell it to run, I get a slightly different error message:
Could not find test executor with URI 'executor://nunittestexecutor/'. Make sure that the test executor is installed and supports .net runtime version 4.0.30319.18010.
This is kind of perplexing because I have the NUnit Test Adapter installed. I'm not seeing anything similar to my issue on the launchpad page for the test adapter.
I'm not really sure where I should proceed from here. If this doesn't work I don't mind reworking my project to use xUnit.net, Microsoft's unit testing framework or something else. It would be pretty awesome if I could get NUnit working though.
Thanks!
I have a Windows 7 Phone app which had the same issue that you have. My solution was to create a separate "linked" project which compiles the code using the standard .net libraries. The linked project will have no issues with unit test / NUnit.
See the following for more information:
http://msdn.microsoft.com/en-us/library/ff921109(v=pandp.40).aspx
http://visualstudiogallery.msdn.microsoft.com/5e730577-d11c-4f2e-8e2b-cbb87f76c044/
I've ported the app to Windows 8 and have no problems running my test cases.
I've just hit the same error message while creating unit tests for an Universal App (W81 + WP81). The only solution here was to stop using NUnit and use MSTest only.