I'm using an application that uses Visual Studio and C# for it's built-in scripting. I want to use NUnit for testing but the environment doesn't understand nuget packages or add-on dll's so it discards anything that isn't source code each time it saves and reloads a project.
I was hoping that I might be able to get around this by including the full NUnit source code in a folder in the C# project and perhaps using something like the lite-runner to run the tests.
Any advise on how to achieve this?
Related
I recently took over a automation project that was written in .NetCore 3.1 using XUnit/Selenium. The Project that houses the code is a console application, not a class library so DLL of the tests are not created. I've had experience getting JAVA Maven based into Jenkins and running each tests a a standalone build in Jenkins but with this C# version, I am not sure how to proceed.
All of their automation is in one Project of the solution, broken down to cs files with a Class in each one hold all the FACT/THEORY Tests.
With .Net Framework, you can target the dll of each test to run it but in this case, I cannot see how to do this without the DLL. They essentially want to target the test Class in each file and run it as a build in Jenkins.
Is this even possible or do we need to convert it to a Class Library to get it to work in Jenkins? The company does NOT want to change it to a Class Library if that can be done.
I know that they will need to install MSTest and the plugin Active Choice Parameter to target their appsettings.json file as well.
Try to change <OutputType>Library</OutputType> to your test project .cproj file
My example for net5.0
I am using VS2019 Professional to develop a Xamarin.Forms app. The project solution consists of the typical head projects which deploy to specific platforms, and the common cross-platform project that contains the bulk of the solution's code. I am trying to find some way, if possible, to run performance tests on the common cross-platform project, which builds to a .NET Standard DLL.
Xamarin currently does not have any tooling available to profile the platform-specific app using the DLL, so I need to find some other way. I have unit tests for this DLL, but there doesn't seem to be any support for profiling unit tests in VS2019. I have tried profiling the vstest.console application that runs the unit tests that test my DLL, but the only option available is to instrument vstest.console, which will do me no good either (obviously don't want to go mucking around with the guts of the test runner!). At this point it seems the only option is to develop an additional test console application and profile that, but I just wanted to check if anyone has encountered a similar use case and found a more elegant solution?
The setup is like this:
A Xamarin.Android application, which depends on Android class library
(at least that's what the template is called in VS)
Said class
library, the purpose of which (not entirely relevant, but FYI) is
interfacing with a REST service and has a dependance on the famous
Newtonsoft.Json NuGet package.
An NUnit test project for said
library.
IDE is Visual Studio 2017, latest version.
If you build and deploy the app on the phone, everything is fine.
However, if you try to run tests from the tests project, it says that it can't find the Newtonsoft library.
I've even managed to find a sort of reason: when the library gets built, it's dependancies aren't packed inside, and they are not copied to build directory.
When .apk is built for the phone, the dependancies ARE getting packed inside.
However, when NUnit project builds itself, it only takes the library, and the dependancies are nowhere to be found.
However, there's no interface to control the behaviour of NuGet "Package Reference" type dependencies (blue ones), the properties window is empty for them. And I found no way to add NuGet packages to this kind of project as a ".config" type of dependancy (grey one).
There is a workaround - you can add the Newtonsoft package to the NUnit test project, then it gets copied to the build directory and the Android library works with it, however it doesn't feel right to me. Tests don't need that reference and it has no business in that project.
How to control NuGet packages in Android Class Library?
Your workaround is the correct solution, you don't need to worry too much about it.
That is because the Newtonsoft package is not used directly in your NUnit test project, so Visual Studio / MSBuild doesn't know if your test project needs this Newtonsoft library. In order to avoid reference pollution in NUnit test project, Visual Studio / MSBuild tries to only bring references over into NUnit test project that it detects as being required by project Xamarin.Android application.
So, to resolve this issue, we often add Newtonsoft to the test project or give a copy task to copy it to the test project.
See This Thread for some more details.
Looking for an answer to another question I now found info that my described behaviour is a known problem, described by .NET developers here:
https://github.com/dotnet/standard/issues/481
First of all, I don't know much about Roslyn. I went through a few tutorials hot to generate code and how to parse a string containing code.
So far, everything is clear to me.
Here is my question:
I'm using dotnet core 1.0.1 on Linux.
I created a new project with some interfaces defining some properties.
What I want to do is to create a program in which I can load the project, run trough the interfaces (*.cs files) and generate some code.
My problem is, I don't know how to load/open a c# project with Roslyn.
The tutorials I found are using a windows environment. These samples doesn't work on my environment because there are some dependencies to MSBuild or Visual Studio. I read and tried some things about the AdhocWorkspace, but I didn't manage to open an existing solution this way.
Can anyone give me a hint how to start?
Is it possible to open/load a project (*.csproj) and run through all *.cs-files?
Thanks in advance.
Currently, there is no good way to open .Net projects using Roslyn on .Net Core.
See this issue on the Roslyn repo, where the recommended solution is to use code from the Omnisharp project.
I'm attempting to write tests with NUnit3 as part of some tech-debt migrations. I created a new project within an existing solution. Using nuget I added NUnit and NUnit.Console as per the instructions on github. (I also added the NUnit 3 Test Adapter extension to Visual Studio 2015, but I'm fairly sure that has no bearing on my current situation).
After adding the nuget packages I attempted to import the TestFixture attribute, however, visual studio isn't recognizing the NUnit.Framework namespace and I can't import anything.
The only thing I could thing to fix it was to add the reference manually. There too I was blocked by NUnit not being available.
I'm somewhat at a loss as to how to move forward. How do I proceed and fix the missing reference?
Update: The project I created was of type Unit Test Project, however I've gone ahead and create a Console Application and Class Library. I attempted to add NUnit via nuget to each of them and all of them have had the same result.
Update: Other nuget dependencies seem to install correctly with no discernable difference.
This is only a pseudo solution, as I don't know what the actual issue is. If anyone else comes across a better fix than my work-around I'll be glad to select it if it works for me down the line.
At the time of this writing, the latest version is 3.4.1. I forced nuget to downgrade to 3.4.0 for both the packages NUnit and NUnit.Console and violĂ the namespace is available as you'd expect any nuget package.