Nunit malfunction for tests in C# - c#

I have transitioned my test project from Visual Studio 2010 to 2015.
Execution of the tests in earlier version was fine since it was Mbunit. In the new version is used Nunit 3.4.1. I do not see any problem in my code. Whenever I want to run test I receive Message: No arguments were provided.
Here is the code of test that have worked fine with MbUnit
[Test]
[TestCaseId(456123)]
[Priority(PriorityLevel.Critical)]
public void ExpiredJobViewPageUi(string channel, SeleniumWebDriverDeviceType seleniumWebDriverDeviceType,string widgetType) {
TestRunner.RunTest(MethodBase.GetCurrentMethod(), channel, seleniumWebDriverDeviceType, webDriver => {
//Test body
ReportLog.WriteLine("Step 1 - Create new flow.");
var flow = new StandardFlowModel<JobModel>(channel, webDriver, ReportLog.WriteLine);
ReportLog.WriteLine("Step 2 - Go to .");
var expPage = flow.GoToExpirationPage(123);
expPage.WaitPageIsLoaded(10);
....
When I click on Run Selected Test in the Text Explorer in Visual Studio 2015 I got the message No arguments were provided.
Can anybody help me what is wrong? Even though there is no chance to set break point to figure out what is going on.

the problem was that I missed some input parameters in [] brackets. When I dig into TestRunner and debugged it I found that I need to specify [Combination("parm", SeleniumWebDriverDeviceType.Desktop, "Popular Articles")]
Thank you for your hints!

Related

Visual Studio IDE0059 C# Unnecessary assignment of a value bug?

I have the following C# Code (I reduced it to the bare minimum to simplify it). Visual Studio 2019, .NET Framework 4.7.2.
public void Demo()
{
ReportStart();
var success = false;
try
{
int no = 1;
switch (no)
{
case 1:
default:
break;
}
DoSomething();
success = true;
}
finally
{
ReportEnd(success);
}
}
From my understanding, there is nothing wrong about it. The function may fail (I don't want to catch it) but before leaving, it will report successful execution to another method. When debugging, it does exactly what it should.
Interestingly, Visual Studio 2019 will report the following:
When I follow the suggestion by choosing "Remove redundant assignment", it will remove the line success = true;, effectively changing the outcome!
Now what is the switch/case for, you'd ask? When removing it, the recommendation disappears:
Is there any reason for that, or is it a bug in Visual Studio?
It seems to be a known issue with Roslyn and Visual Studio 2019 16.4, please refer to the GitHub issues #39755 and #39344.
The milestone is set to the version 16.5 Preview 2, so it was already fixed and you can try the preview 2 of 16.5 version or wait for stable one (personally, I'm not using a Preview versions)

VBScript GetObject() not working if called from C# WPF application

I have the following VBScript code in MyScript.vbs:
Dim myApp
Set myApp = GetObject(,"ViewDraw.Application")
I call it from a PowerShell command line, like so:
cscript MyScript.vbs //I
This works as expected; myApp is set to the process I'm looking for and I'm able to interact with it.
Here's some C# code that attempts to do the same thing:
var script = new Process();
script.StartInfo.FileName = "cscript";
script.StartInfo.Arguments = #"<MyWorkingFolder>\MyScript.vbs //I";
script.StartInfo.CreateNoWindow = true;
script.StartInfo.RedirectStandardOutput = true;
script.StartInfo.UseShellExecute = false;
script.Start();
//Read anything sent out by program
string output = script.StandardOutput.ReadToEnd();
script.WaitForExit();
VBScriptResult result = new VBScriptResult();
result.returnCode = script.ExitCode;
result.stdOut = output;
return result;
When I execute the C# code, the VBScript fails on the GetObject() call. There have been similar SO questions, and I've tried their suggestions. One suggestion was to explicitly call either the 32bit or 64bit version of cscript. Neither worked, however.
This hasn't always been an issue. The code is a couple of years old now and has worked in the past. It's possible that an update to Visual Studio 2017 somehow caused this problem. I'm currently running version 15.3.5.
I've been stuck on this issue for a week now, so any help is greatly appreciated!
The problem is with Visual Studio 2017, probably a result of taking update 15.3 or later. The same code works fine in VS 2015 Update 3.

NUnit is not failing test with dynamic keyword of .Net 4.0

I am using NUnit with Visual Studio Express Edition 2010 for C#, Now, normally test works fine. But whenever I try to use Massive.cs, which is open source api to access database. Test fails from that file only. Now, if I run the application, api is working fine. I have created a different library file to access data base.
I seriously don't understand the error. It is just giving error that object reference is not set to an object. But if I run the code, it works fine. I am using dynamic keyword as shown in link of api above. Does that making problem with NUnit ?
Is there any other way to test in this type of Scenarios?
Here are the further details of the code,
Test class is like this
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var items = item.All();
Assert.AreEqual("Maggi", items.FirstOrDefault().Name);
Now, I have put test here. Which gives error like shown in image,
Now if I run code in console application, then code is working fine, code snippet is given below
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var result = item.All();
foreach (var i in result)
{
Console.WriteLine(i.Name + i.Description);
}
Console.Read();
Here, code is working and same thing is not working with NUnit Test. Please have a look and help me out. Please let me know if any further information is needed from my side.
Most probable explanation is that you haven't set up your connection string in the test project.
If you are using NUnit, just put it in app.config of your test project.
Solved... There is a issue with NUnit Testing. It was not taking config file pefectly. So, I made two changes. Changes I have done in Project setting.
First change is to change Application Base to bin\debug just give application base as this and then config file to .config to .exe.config and things are up and running. :)

Rhino Mock vs debug mode?

my problem is following:
I have ms unit test which uses stubbed http context for mvc routing tests. But one part of code (which uses rhino mock) is problematic:
var httpContextMock = MockRepository.GenerateStub<HttpContextBase>();
httpContextMock.Stub(c => c.Request.AppRelativeCurrentExecutionFilePath)
.Return(url);
In debug mode, second line throws an exception:
Why such an error occurs ? While tests are fired without debugger, everything works fine.
Regards
This is really weird. What's strange to me is that your code works in non-debug mode. The Request property is not stubbed, so you can't really know what it would return. You may try the following:
var httpContextMock = MockRepository.GenerateStub<HttpContextBase>();
var httpRequestMock = MockRepository.GenerateStub<HttpContextBase>();
httpContextMock.Stub(c => c.Request).Return(httpRequestMock);
httpRequestMock.Stub(c => c.AppRelativeCurrentExecutionFilePath).Return(url);
I was having this issue with mine as well, and fixed it by deleting the .suo file for the solution.
I seem to also get different exceptions when toggling the Break when Common Language Runtime Exception is thrown setting, which is stored in the suo file (Debug Menu -> Exceptions)
The problem is your stub method. By using only .Return() it will give this value back only once. If you don't care about how many times the stub should return the value you should use .Return().Repeat.Any().

CodedUI Test: Keyboard.SendKeys not working

I'm trying to use the CodedUI Test feature of Visual Studio 2010.
I've got a problem while replaying the various actions for one of my html component. The Keyboard.SendKeys generated do not work (like if there was no input).
The code generated is :
// Type '{F4}{F4}{F2}titre{Enter}' in 'SaisieSD_DS' custom control
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);
If I replace the call to Keyboard.SendKeys by a call to System.Windows.Forms.SendKeys.SendWait, it does work.
I was thinking about a problem due to a loss of focus. However, if i do something like uISaisieSD_DSCustom.SetFocus(), it doesn't change the behavior.
Do you have any idea ?
thx.
Have you tried
uISaisieSD_DSCustom.WaitForReady()
Or one of the other waitfors?
Is it failing on this line? Or is it failing afterward due to this not working correctly?
You can also use the following to wait for all threads to complete before proceeding:
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.AllThreads;
Keyboard.SendKeys(uISaisieSD_DSCustom, this.Params.UISaisieSD_DSCustomSendKeys, ModifierKeys.None);
Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
Just make sure you include the last line to turn it back to UIThreadOnly, or it will slow everything way down.
Visual Studio CodedUI Test searches for a control and sends those keys to it. In your case the control is 'uISaisieSD_DSCustom'.
You can try using:
Keyboard.SendKeys(this.Params.UISaisieSD_DSCustomSendKeys);
OR
Keyboard.SendKeys("{F4}{F4}{F2}titre{Enter}");
After typing the URL if we want to send the enter key then the below code works in Coded UI
Keyboard.SendKeys("{Enter}");

Categories

Resources