Cake Running Nunit 3 using DotNetCoreTest Is Failing - nunit-3.0

Task("Nunit")
.Does(() => {
DotNetCoreTest("D:\Workspace\Proj14\test\test\WebAutomation\NUnit\UserManageLMTWS.cs", );
});
Currently have by build.cake defining the task as such as listed in the https://cakebuild.net/api/Cake.Common.Tools.DotNetCore/DotNetCoreAliases/8191BBC4 example. I don't have any settings, as I guess I'm building into Debug instead of Release, but I am getting the following errors when running the task:
Error: Bootstrapping failed for 'D:/Workspace/Proj14/test/test/Nunit'.
Nunit, line #0: Could not find script 'D:/Workspace/Proj14/test/test/Nunit'.
Do I need to pass NUnit into the DotNetCoreTest method somehow?

DotNetCoreTest is meant to test projects and not individual files.
So you specify either the <PROJECT> | <SOLUTION> | <DIRECTORY> file i.e.
DotNetCoreTest("./test/Project.Tests/", settings);
DotNetCoreTest("./test/My.sln", settings);
DotNetCoreTest("./test/Project.Tests/Project.Tests.csproj", settings);
DotNetCoreTest calls to the .NET SDK CLI command dotnet test.
The error you're receiving though is because the path to the specified script is wrong / doesn't exist. There's no file called D:/Workspace/Proj14/test/test/Nunit which is why error message says Could not find script 'D:/Workspace/Proj14/test/test/Nunit'

Related

How to provide an HttpClient to ktor server from the outside to facilitate mocking external services?

I am trying to provide an HttpClient from the outside to my ktor server so that I can mock external services and write tests, however I get this exception when I run my test:
Please make sure that you use unique name for the plugin and don't install it twice. Conflicting application plugin is already installed with the same key as `Compression`
io.ktor.server.application.DuplicatePluginException: Please make sure that you use unique name for the plugin and don't install it twice. Conflicting application plugin is already installed with the same key as `Compression`
at app//io.ktor.server.application.ApplicationPluginKt.install(ApplicationPlugin.kt:112)
at app//com.example.plugins.HTTPKt.configureHTTP(HTTP.kt:13)
at app//com.example.ApplicationKt.module(Application.kt:14)
at app//com.example.ApplicationTest$expected to work$1$1.invoke(ApplicationTest.kt:39)
at app//com.example.ApplicationTest$expected to work$1$1.invoke(ApplicationTest.kt:38)
and thats a bit unexpected to me because I am not applying the Compression plugin twice as far as I can tell. If I run the server normally and manually call my endpoint with curl then it works as expected. What am I doing wrong?
I added a runnable sample project here with a failing test.
sample project
official ktor-documentation-sample project.
The problem is that you have the application.conf file and by default, the testApplication function tries to load modules which are enumerated there. Since you also explicitly load them in the application {} block the DuplicatePluginException occurs. To solve your problem you can explicitly load an empty configuration instead of the default one:
// ...
application {
module(client)
}
environment {
config = MapApplicationConfig()
}
// ...

ASP.NET Core error on building with NSwag Error MSB3073

When I build the application, I get the following error message
The command "dotnet "C:\Users\Adminuser\.nuget\packages\nswag.msbuild\13.0.6\build\../tools/NetCore22/dotnet-nswag.dll" run /variables:Configuration=Debug" exited with code
-2147450730. Northwind.WebUI C:\Users\Adminuser\Documents\Visual Studio 2017\Projects\NorthwindTraders-master\Northwind.WebUI\Northwind.WebUI.csproj 60
Any Idea how to fix this issue?
Swagger doesn't like it when two or more endpoints in the same Controller share the same name. make use of routing attributes and make sure they are unique.
Try to install NSwagStudio then re open your visual studio.
That's should solve your problem.
If it's still not working
give a look about your output console when you try to compile your project, you should see something like this
1>Executing file 'nswag.json' with variables 'Configuration=Debug'...
1>Launcher directory:
C:\Users\Shadow.nuget\packages\nswag.msbuild\13.1.6\tools\NetCore30
You should have a file called dotnet-nswag.exe in your c:\user...\tools\netcore30 directory.
Put this exe in your environnement path.
Re open visual studio and your error should be gone.

Fatal error running unit test in Yii app

This Question is local to my situation and not resolved (yet). But if you are experiencing this problem, the trouble shooting steps may give you a good path to start on.
I want to run a unit test in a Yii web application on localhost, which is running via WampServer 2.1 on Windows 7.
<?php
class LittleTest extends CTestCase
{
public function testApprove()
{
$value1 = "1";
$this->assertEquals($value1,$value1);
}
}
?>
I receive a fatal error when I try to run the test. Here is how I run it, on the Windows command line:
C:\wamp\www\app\protected\tests>
C:\wamp\www\app\protected\tests>cd unit
C:\wamp\www\app\protected\tests\unit>phpunit LittleTest.php
I receive (along with some stack trace lines):
PHP Fatal error:
class 'CTestCase' not found in [path to file]\LittleTest.php on line 4
Trouble shooting steps to this point:
The app runs. The default index page of the app looks good and I have used the gii tool to create a model class.
From command line, I can see php and phpunit are available (and I've been over my pear install to make sure it's all good):
C:\wamp\www\app\protected\tests>
C:\wamp\www\app\protected\tests>phpunit --version
PHPUnit 3.7.13 by Sebastian Bergmann.
C:\wamp\www\app\protected\tests>
C:\wamp\www\app\protected\tests>php --version
PHP 5.3.5 (cli)
... etc
display_errors is turned on. display_startup_errors is turned on.
I tried renaming the class so that name did not match the document name:
class LittleTestTweak extends CTestCase
I'm not sure of the precise command that runs the test, so I have tried variants like:
php LittleTest.php
Also I've tried running it various places in the folder structure. Here is the immediate structure:
/tests
| bootstrap.php
| my_tree.txt
| phpunit.xml
| WebTestCase.php
|
|---- /fixtures
|---- /functional
| SiteTest.php
|
|---- /report
`---- /unit
LittleTest.php
I also checked my php.ini for the path to PEAR; as far as I can tell, it's correct (but how can I test it?):
include_path=".;C:\wamp\bin\php\php5.3.5\PEAR;C:\wamp\www\app
More Info
In response to this:
cd wamp\www\app\protected\tests
phpunit unit\LittleTest.php
I receive this:
Warning: require_once(PHPUnit/Extensions/SeleniumTestCase.php):
failed to open stream: No such file or directory in
C:\wamp\www\yii\framework\test\CWebTestCase.php on line 12
Call Stack:
0.0007 339624 1. {main}() C:\wamp\bin\php\php5.3.5\phpunit:0
0.0164 698440 2. PHPUnit_TextUI_Command::main()
C:\wamp\bin\php\php5.3.5\phpunit:46
0.0164 698856 3. PHPUnit_TextUI_Command->run()
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:129
0.0164 698856 4. PHPUnit_TextUI_Command->handleArguments()
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:138
0.0289 1220944 5. PHPUnit_TextUI_Command->handleBootstrap()
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:606
0.0300 1233328 6. PHPUnit_Util_Fileloader::checkAndLoad()
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\TextUI\Command.php:778
0.0330 1233424 7. PHPUnit_Util_Fileloader::load()
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Util\Fileloader.php:76
0.0334 1238096 8. include_once
('C:\wamp\www\app\protected\tests\bootstrap.php')
C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Util\Fileloader.php:92
0.0412 1520256 9. require_once
('C:\wamp\www\app\protected\tests\WebTestCase.php')
C:\wamp\www\app\protected\tests\bootstrap.php:8
0.0413 1520520 10. YiiBase::autoload()
C:\wamp\www\yii\framework\YiiBase.php:0
0.0423 1543904 11.
include('C:\wamp\www\yii\framework\test\CWebTestCase.php')
C:\wamp\www\yii\framework\YiiBase.php:395
Fatal error: require_once(): Failed opening required
'PHPUnit/Extensions/SeleniumTestCase.php'
(include_path='.;C:\wamp\bin\php\php5.3.5\PEAR\pear;C:\wamp\bin\php\php5.3.5\pear')
in C:\wamp\www\yii\framework\test\CWebTestCase.php on line 12
Call Stack:
0.0007 339624 1. {main}() C:\wamp\bin\php\php5.3.5\phpunit:0
0.0164 698440 2. PHPUnit_TextUI_Command::main()
...et cetera...
The failed requirement is PHPUnit/Extensions/SeleniumTestCase.php. I wonder if the issue is that PHPUnit is installed locally under C:\wamp.
I opened my php.ini and added to include_path: C:\wamp\bin\php\php5.3.5\PEAR\PHPUnit\Extensions. Restarted wamp. No change in error reporting.
RESOLUTION
My security setup uses DansGuardian and I had neglected to loosen the settings for banned extension types, which blocks file downloads. In fact I don't care to ban any types, and modifying that file allows everything to work. Woops, that's my Linux set. PHPUnit is working there, and it is working on WAMP also. Recreating the steps on WAMP is impossible; but I do know I had to open cmd.exe as administrator and pear update-channels, pear upgrade-all, etc. I also had to clear pear's cache at one point, and I had to overcome an issue with curl recognition to install Selenium:
pear install --force phpunit/PHPUnit_Selenium
To run unit tests in Yii with phpunit, you'll need to let phpunit load the protected/tests/bootstrap.php file which basically sets up a configuration, and autoloads the required classes (mainly pertaining to testing). The bootstrap.php file loads yiit.php which actually autoloads the required classes.
Now we can load all this configuration either by command line options when running phpunit, or let the configuration be read automatically through the protected/tests/phpunit.xml file.
For the latter method, the directory from where phpunit is invoked should have the phpunit.xml file in it, and in Yii default webapp, this directory is protected/tests. Therefore you need to do the following to run your tests:
cd wamp\www\app\protected\tests
phpunit unit\LittleTest.php

Does mono 2.8 support 'dynamic' keyword?

I tested IronPython on mono 2.8 with the code in the book Professional IronPython p.315 listing 15-3.
using System;
using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting.Hosting;
namespace Method2
{
class Program
{
static void Main(string[] args)
{
// Obtain the runtime.
var IPY = Python.CreateRuntime();
// Create a dynamic object containing the script.
dynamic TestPy = IPY.UseFile("TestClass.py");
// Execute the __test__() method.
TestPy.__test__();
}
}
}
I see it's compiled OK, and run without a problem on Windows 7, whereas the mono 2.8 gives me the following error message.
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
`Microsoft.Scripting.Hosting.ScriptScope' does not contain a definition for `__test__'
at (wrapper dynamic-method) object.CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1
(System.Runtime.CompilerServices.CallSite,object)
at Method2.Program.Main (string[])
I thought Mono 2.8 supports C# 4.0 which has the dynamic keyword, but I see that the 'dynamic' keyword is not fully supported with mono.
Is this a bug of Mono 2.8?
ADDED
This is the python script.
# The class you want to access externally.
class DoCalculations():
# A method within the class that adds two numbers.
def DoAdd(self, First, Second):
# Provide a result.
return First + Second
# A test suite in IronPython.
def __test__():
# Create the object.
MyCalc = DoCalculations()
# Perform the test.
print MyCalc.DoAdd(5, 10)
# Pause after the test session.
raw_input('\nPress any key to continue...')
This is the command that I used
dmcs Program.cs /r:System.Core /r:IronPython.dll /r:IronPython.Modules.dll /r:Microsoft.Dynamic.dll /r:Microsoft.Scripting.dll /r:Microsoft.CSharp.dll
It compiles well, but it still breaks when I run the execution binary. Do I need to have all the dlls in the same directory where the execution binary locates?
The fact that you are getting a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException means that the dynamic keyword worked. The problem you are having is that IPY.UseFile("TestClass.py"); is returning a ScriptScope that doesn't see your test method. So the problem lies with your python source or how you are including IronPython with mono.
The dynamic keyword is certainly supported by Mono 2.8 when using the C# 4 profile.
I guess my question is how you are building this sample?
Just for kicks, I just pasted your sample into MonoDevelop. I had to tell MonoDevelop to use C# 4 instead of C# 3.5 first of all.
The dynamic keyword was introduced in C# 4 obviously.
Also, I did have to include a few assembly references: System.Core, IronPython.dll, IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, and Microsoft.CSharp.dll. I am not sure if I needed them all.
If you are building from the command-line you need to use 'dmcs' as the compiler (to indicate the .NET 4 profile) and you need to include the assembly references.
It builds without problems with this configuration (for me at least).
I am responding to this question with respect to Mono 2.10.
I could successfully build and execute the code from command line on Windows 7 without using MonoDevelop. Here are the steps:
Install Mono 2.10.8 on Windows 7.
Install IronPython 2.7.2.1.
"C:\Program Files\Mono\bin" or equivalent and "C:\Program Files\IronPython 2.7" or equivalent should be part of system path.
Both TestClass.py and Program.cs should be in the same folder.
From the dos prompt, corresponding to the folder where TestClass.py and Program.cs exists, execute setmonopath batch file.
From the same dos prompt execute the following command:
dmcs Program.cs /r:System /r:"C:\Program Files\IronPython 2.7\IronPython.dll" /r:"C:\Program Files\IronPython 2.7\IronPython.Modules.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Dynamic.dll" /r:"C:\Program Files\IronPython 2.7\Microsoft.Scripting.dll" /r:"C:\program Files\IronPython 2.7\Microsoft.Scripting.MetaData.dll" /r:Microsoft.Csharp
Program.exe should be successfully generated and the same can be executed without any error message.

Team Build sends error when trying to compile a Structuremap method

I'm getting a strange error when trying to compile a solution that is using StructureMap on Team Build.
When I try to compile the solution locally on Visual Studio it works fine, but when trying to queue a new build in Team Build I get the following error:
Overload resolution failed because no accessible 'Use' can be called with these arguments:
The line of code that gets this error is the second one:
ForSingletonOf(Of ISessionFactory)().Use(NHibernateSessionFactory.SessionFactory)
Me.For(Of ISession)().lifecycleIs(New HybridLifecycle()).Use(Function(x) x.GetInstance(Of ISessionFactory)().OpenSession())
It's a standard registration for the NHibernate session, so I don't really get why this error pops up.
Thanks in advance for the clues.
Make sure you have the correct version of NHibernate on the build server, and that your hint paths are all appropriately set in your project file. We haven't had this specific issue (as we're not using NHibernate), but we've had weird issues like that being related to version mismatches of "infrastructure" DLLs between local and build.