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
Related
I am using MSTest project to automate my system. The test project work fine. But I need to run the test project in my production with out installing visual studio.
So that I am using VSTest.Console.exe command-line.
My Login method as below
[TestMethod]
[TestCategory("SmokeTests")]
public void Can_login_with_Empty_UserName()
{
Login(TestContext.Properties["UserName"].ToString(), TestContext.Properties["Password"].ToString());
}
and my vstest.console command as below
vstest.console MyPath\SmokeTests.dll /Tests:Login /Settings: PathToSettingFile\tests.runsettings
when I run this command it will give me
"System.NullReferenceException: Object reference not set to an instance of an object." Error
But if I change my method like below
[TestMethod]
[TestCategory("SmokeTests")]
public void Can_login_with_Empty_UserName()
{
Login("Admin", "1234");
}
Above code will work properly.
So the problem is
TestContext.Properties["UserName"].ToString()
When I run the test case through Visual Studio no issues.
Any idea why /Settings: PathToSettingFile\tests.runsettings cannot load runsettings file running through the vstest.console command.
Thank you.
I hope you can help me get my xUnit project up and running.
using SortingAlgorithms;
using Xunit;
namespace SortingArlgorithmsTest
{
public class SortingAlgorithmsTest
{
[Fact]
public void SwapTest()
{
int[] values = { 1, 0 };
int[] expected = { 0, 1 };
SelectionSort.Swap(values, 0, 1);
Assert.Equal(values[0], expected[0]);
}
}
}
As you can see, a simple example of a test, but running it, leads to following messages in Output:
Exception thrown: 'System.IO.FileLoadException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileLoadException' in Microsoft.VisualStudio.TestPlatform.Common.dll
and this:
[11/28/2018 09:45:52 Informational] ------ Run test started ------
[11/28/2018 09:46:02 Warning] No test is available in <folders>\SortingArlgorithmsTest.dll.
Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[11/28/2018 09:46:03 Informational] ========== Run test finished: 0 run (0:00:10.5896982) ==========
following NuGet Packages are installed:
I've already searched on my own, but have not found a solution to get my tests up and running, for example:
C# .NET Core How to debug System.IO.FileNotFoundException in System.Private.CoreLib.dll?
I hope you can help me. :)
edit:
ok i moved from trying to run the test from within the IDE to command with dotnet test... and something strange shows up... the folder is not there but in windows explorer it is... Maybe it is because it is not fully synced ( i use the cloud service of my university to store my private projects)
intelliJ with jUnit is not such a b***h....
for fun cmd: dir shows all old folders which are not synced anymore, but non of the folders which are in sync (or not fully synced)... in Windows explorer i have all folders...
I did a Clean then Build of my Unit Test project and it worked with no particular reason. Hope it helps.
I just started using visual studio 2015 & c# language so I'm a complete newbie. anyway I was trying to write a web testing project with selenium (references) in vs2015 and the first few tutorials were relatively easy to understand, that's what I got:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support;
namespace testsite
{
[TestClass]
public class firsttest
{
IWebDriver driver;
String url = "http://www.somewabpage.com";
[TestInitialize]
public void setup()
{
//Starting the browser and visiting the site
driver = new ChromeDriver();
driver.Navigate().GoToUrl(url);
}
[TestCleanup]
public void Cleanup()
{
//after the test
driver.Quit();
}
[TestMethod]
public void testtingsite()
{
//Here we write the actual test
}
}
}
I know it's not much, but the problem is when ever I go to test explorer >> run all then I get this:
------ Run test started ------
Cannot discover test extensions installed by NuGet. The NuGet service is not available. Tests may not be found due to missing test adapter extensions.
NUnit VS Adapter 2.0.0.0 executing tests is started
Loading tests from C:\Users\kkkkkk\Documents\Visual Studio 2015\Projects\testsite\testsite\bin\Debug\testsite.dll
Run started: C:\Users\kkkkkk\Documents\Visual Studio 2015\Projects\testsite\testsite\bin\Debug\testsite.dll
NUnit VS Adapter 2.0.0.0 executing tests is finished
========== Run test finished: 1 run (0:00:06.5556584) ==========
White it should open the chrome browse, visit the url and then quits chrome, which doesn't happen at all. I re-tested it again with the same result only this time it says in the test explorer window that the test has failed and that's it, when I click on the testsite below the failed test (still in the test explorer window) i get the following message :
Test Name: testtingsite
Test FullName: testsite.firsttest.testtingsite
Test Source: c:\users\kkkkkk\documents\visual studio 2015\Projects\testsite\testsite\UnitTest1.cs : line 34
Test Outcome: Failed
Test Duration: 0:00:00.1350487
Result StackTrace:
à OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String executableName, Uri downloadUrl) dans c:\Projects\webdriver\dotnet\src\webdriver\DriverService.cs:ligne 243
à OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService() dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriverService.cs:ligne 146
à OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options) dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriver.cs:ligne 80
à OpenQA.Selenium.Chrome.ChromeDriver..ctor() dans c:\Projects\webdriver\dotnet\src\webdriver\Chrome\ChromeDriver.cs:ligne 71
à testsite.firsttest.setup() dans c:\users\kkkkkk\documents\visual studio 2015\Projects\testsite\testsite\UnitTest1.cs:ligne 19
Result Message: Initialization method testsite.firsttest.setup threw exception. OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The chromedriver.exe file does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html..
okay that's the message, any ideas on how to solve the issue I really need help );
modification_1
so I've modified the code (thanks to #Leon) I added the following string DRIVER_PATH = #"C:\Projects\webdriver\dotnet\src\webdriver\chrome\chromedriver"; to [TestClass] right below the string url = "http://..."; and also add DRIVER_PATH like this driver = new ChromeDriver(DRIVER_PATH); in the [TestInitialize] but it's still not running the chrome browser!!?
You need download chrome driver.
chrome driver link
string DRIVER_PATH = #"C:\...\chromedriver";
IWebDriver driver = new ChromeDriver(DRIVER_PATH);
driver.Navigate().GoToUrl(url);
so the problem was like #leon mentioned it in the chromedriver, but although I used his path method (described in modification_1) it didn't work, what actually did work and solved my problem (without changing the first code, before mofication_1) was the installation of the selenium chromedriver from visual studio 2015, I went to references >> right click >> go to manage Nuget package >> and then typed selenium chromedriver in the search bar and boom all I had to do was click on install, internet connection was required. if you can't see the nuget manage packages then you need to download and install it and then restart visual studio to see it.
Just add the driver reference as per your browser specification like chromedriver, edgedriver. Please note "not mention any driver path".
namespace UnitTestProject3
{
public class UnitTest1
{
IWebDriver wb;
String url = "http://www.yahoo.com";
[Fact]
public void TestMethod1()
{
wb = new ChromeDriver();
wb.Navigate().GoToUrl(url);
}
}
}
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.
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.