NUnit tests all failed in Visual Studio Code (MacOS) - unity3d

I just started using VSCode (MacOS) and no matter the assertion, it always failed but it's not throwing any errors or warning to indicate that I set it up wrong. I have the following test unit:
using NUnit.Framework;
public class SampleTests
{
[Test]
public void SimpleAssertion() {
Assert.That(true);
}
}
Console output:
Running test SampleTests.SimpleFail...
Test failed
How do I run NUnit inside VSCode properly?

Related

Retry attribute is not working as expected - NUnit Framework

We are using C# Selenium and NUnit framework for our test automation. Sometimes some test cases will fail in dev environment during execution due environmental issues. I was trying to re-run the failed ones, by using Retry attribute. But it didn't work ( I have kept assertion failures as well)
Could you please have a look the below code
[TestFixture]
public class UITests : BaseClassProtractor
{
[SetUp]
public void Setup()
{
//**Call chrome driver and open app url set up**//
}
[Test]
[Retry(1)]
public TestMethod1()
{
//** Write test Steps
}
[TearDown]
public void TearDown()
{
Drivers.TryRemove(TestContext.CurrentContext.Test.FullName, out var localDriver);
localDriver?.Quit();
}
}
Thanks,
Khaja Shaik.
[Retry(1)] indicates that the test should only be run once! That is, it won't be retried if it fails. Use [Retry(2)] as a minimum.
If you continue to get failures, we need to see the exact failure message.

How to debug JavaScript tests in JHipster applications using Karma?

I have a simple monolithic application generated using JHipster v4.10.1 with front-end using Angular 4.x. To run JavaScript unit tests, as suggested in the documentation I ran
./node_modules/karma/bin/karma start src/test/javascript/karma.conf.js --debug
The command runs the tests, reports coverage summary and exits, whether tests all pass or some test fail does not matter. Test run output does show at one point that the debug server is loaded:
21 11 2017 13:41:20.616:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
But because the command exits, the Karma debug server can not be accessed. How to run tests so that Karma console can be used in browser to debug?
Figured out that the magic flag is actually single-run which seems to be true by default. So the main command to run for JS debug is:
yarn test --single-run=false
which in turn runs
$ karma start src/test/javascript/karma.conf.js --single-run=false
With this the command will only exit with explicit kill e.g. with Ctrl+C or Z. Karma debug console can then be accessed on http://localhost:9876/debug.html (assuming default port is not already busy. If it is, test output should tell you which port was chosen).
Additionally you need to disable minimization (and also istanbul config - not sure why) so that you can breakpoint and step through the .ts code in debugger easily. I figured this is done by making following changes in webpack/webpack.test.js file:
Remove following istanbul config from module.rules array:
{
test: /src[/|\\]main[/|\\]webapp[/|\\].+\.ts$/,
enforce: 'post',
exclude: /(test|node_modules)/,
loader: 'sourcemap-istanbul-instrumenter-loader?force-sourcemap=true'
}
Add minimize: false to the LoaderOptionsPlugin under plugins array:
new LoaderOptionsPlugin({
minimize: false,
options: {
tslint: {
emitErrors: !WATCH,
failOnHint: false
}
}
})

ECONNREFUSED Webdriver errors in eclipse when running Protractor

So, I was following this tutorial on getting my existing protractor files imported to Eclipse as Java project, installing angular/protractor configurations on eclipse and running the files:
https://www.youtube.com/watch?v=8dZ3isYcthI
But then I got into the weeds on this error: Error while running conf.js file from Eclipse
In attempt to resolve it, following instructions on the youtube tutorial, I replaced the selenium webdriver folder in Eclipse with the selenium webdriver folder in my node modules folder in AppData by dragging and dropping
Now my conf.js file will not run as protractor on Eclipse even though the file will execute successfully from the command line. Error is:
(node:53640) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[15:11:38] I/launcher - Running 1 instances of WebDriver
[15:11:38] I/hosted - Using the selenium server at http://localhost:4444 /wd/hub
[15:11:39] E/launcher - Error code: 135
[15:11:39] E/launcher - Error message: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
[15:11:39] E/launcher - Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 at ClientRequest. (C:\Workspace\testUltimateQASite\node_modules\selenium-webdriver\http\index.js:238:15)
The js line it is pointing to in the index file is the last line of this function:
request.on('error', function(e) {
if (e.code === 'ECONNRESET') {
setTimeout(function() {
sendRequest(options, onOk, onError, opt_data, opt_proxy);
}, 15);
} else {
var message = e.message;
if (e.code) {
message = e.code + ' ' + message;
}
onError(new Error(message));
}
});
My conf.js file is as follows:
// conf.js
//var jasmineReporters = require('jasmine-reporters');
var os = require('os'); os.tmpDir = os.tmpdir;
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['qaSpec.js'],
//module.exports = {
params: {
url : 'http://phptravels.com/demo/'
/* login: {
url: 'http://phptravels.com/demo/',
username: 'juliel#ibm.com',
password: 'password'
}*/
}
};
The error is basically stating that your Selenium server doesn't seem to be running. Notice how you are seeing a connection refused error.
Please check if you have started the selenium server as described in the official documentation here : http://www.protractortest.org/#/tutorial#setup
For more information on setting up eclipse and protractor you might want to refer here as well :https://github.com/angelozerr/angularjs-eclipse/wiki/Protractor
I tried to understand your project's architecture by reading post several times and still got a bit confused.
I am not sure how do you manage Webdriver?
For Protractor project I would recommend using proper NodeJS project's structure as well as using any JS task runner. Grunt might be a good choice.
There are plenty Webdriver Manager plugins as well as Protractor managers so you will be able to load your project's dependencies and run test with single Grunt command.
UPDATE: this demo project might be useful in understanding the use of Grunt and its dependencies in Angular project's architecture.

I am getting this error "Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure."

While executing this code, it generates an error for chrome which timed out waiting for driver server to start.
package pkg;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ClassLogin {
private WebDriver driver;
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
driver = new ChromeDriver();
driver.get("www.xyz.com");
driver.manage().window().maximize();
}
}
webdriver.chrome.driver needs to be set to a path to chromedriver.exe and not chrome.exe.
You may need to download ChromeDriver - WebDriver for Chrome and then set there system property appropriately.

InteropServices.COMException when running WatiN tests

When I run WatiN tests on our build server they all throw this InteropServices.COMException:
MyTestClassName.MyTestMethodName:
System.Runtime.InteropServices.COMException : Creating an instance of the COM component with CLSID {0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80004005.
I get the same result wether I run them through TeamCity or I run them manually on the server as an administrator using NUnit GUI (2.5).
This is some sample code:
[TestFixture]
public class MyTestClassName
{
private string pageUrl;
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
pageUrl = ConfigurationManager.AppSettings["SiteURL"] + "/Pages/MyPage.aspx";
Settings.MakeNewIeInstanceVisible = false;
}
[Test]
public void MyTestMethodName()
{
using (var ie = new IE(pageUrl))
{
ie.SelectList(new Regex(#"^*DropDownList1*$")).Option("TheOption").Select();
ie.SelectList(new Regex(#"^*DropDownList2*$")).Option("AnOption").Select();
ie.SelectList(new Regex(#"^*DropDownList3*$")).Option("OtherOption").Select();
}
}
}
Any ideas what it can be?
/Joakim
Try running Visual Studio as Administrator.
I also meet the same problem but more strange for me.
I've got a server only for "UI testing" and for many application de WatiN test runs without any problem.
This error only happens for one application and only in CruiseControl (with nant) but not when runing the test with NUnitGUI...
I Finnaly found a solution this morning: I replaced all my call new IE(); to new IE(true) WatiN release note And didn't get the error anymore.
Another fix is to "Enable Protected mode in IE" like described here
Every time IE.Quit was called by WatiN IE would stop responding and then try to recover. Run as admin fixed the problem for me.
Another comment says:
Try running Visual Studio as Administrator
It is actually NUnit that needs to be run as administrator (at least in Windows 7), but the thinking is correct.
I think that the select list is not yet fully loaded and ready, and this is another symptom of the same problem described in this question:
Access denied error ( Visual Studio and WatiN )