VS 2008 -- Using Relative paths in Build Properties - c#

Long story short, I have a test project file (C# project) that contains the NUnit assemblies. When I hit F5, the build properties tell the project to launch NUnit and run the appropriate tests.
However, I work with a team and this project (including the NUnit binaries) are in subversion. Which means that when my partner pulls it down in a different location, the path to NUnit is different and thus it breaks.
Is there a "%PROJECTDIR%" constant or something that I can use in build properties to refer to the NUnit exe and make it work?
Thanks in advance for any help you can give,
Sean

Go into Project - ProjectName settings
Select Build Events
Click Edit Pre-build ... or Edit Post-build ...
Click on Macros >>
Double click on the path or file you need.

Related

SpecFlow Test cannot be run with Playwright.NET

I created a specflow project using c# and playwright. No issues with the code, but the tests do not run When using test explorer on visual studio.
when i run the test, the results always say:
test not run
I installed the nuget packages for playwright and specflow and cannot see any errors. Are there any other components required for the test to run?
I m using playwright.net with c#
any advise would be appreciated
sample feature file:
Feature: feature example
#mytag
Scenario: Open test
Given the test page is open
When I navigate to the links page
Then I will see all the links
thanks
1- Are the tests ignored?
If you have r# Open one of the test files and check if there is a little gray eye-like icon to the left of test method declarations, if so, tests are ignored.
if not on r#, open vs text explorer and check if your tests are there, and if they are, there is something on the window that says they are ignored.
This weirdly happens when your file path is too long (i.e deep in the folder hierarchy, or maybe not so eep, but long folder and file names.
try to move you test project up in the folder hierarchy on the drive.
2- Do you have a test runner for the test framework? i.e nunit test runner?
If you don't see your tests on the test explorer at all, try installing test framework's runner as a vs extension.
Have you tried to move the solution upper in the directory hierarchy?
ie.
c:\projects\mycompany.projects.crmprojects.solution1\project1\testproject....\test.cs
becomes
c:\projects\solution1\project1\test.cs

Visual studio project dependency to other project doesn't copy exe [duplicate]

This question already has answers here:
Copy exe from one project to another's debug output directory
(2 answers)
Closed 5 years ago.
I have a C# solution (visual studio 2017) with two projects lets say A and B, both compiled to exe. Project A depends on project B's exe, I though a dependency to project B would solve this. However, the exe doesn't get copied automatically when build.
Does the dependencies not work for exe's ? Is the only solution to make an post build step ?
I think you want a post-build event.
It sounds like you already have the Project Dependency set up, which is good, because it's important that Project B gets built before Project A. And adding a Project Dependency for Project B, to Project A, is the way to do that.
Here's the documentation for adding/removing Project Dependencies: https://msdn.microsoft.com/en-us/library/et61xzb3.aspx
In Project A you can add a post build event that will copy the Project B exe.
Right Click Project A, and choose "Properties".
Change to the "Build Events" tab.
Add the command: copy "FromPath" "ToPath"
The documentation for the copy command is here: https://technet.microsoft.com/en-gb/library/bb490886.aspx?f=255&MSPPError=-2147217396
If you click "Edit Post-build", you'll get a mini-editor which has a button labelled "Macros".
If you click that "Macros" button then it'll allow you to insert replacement strings in the format $(foo).
These macros allow you to get things like the project or solution folder, so you can easily build paths that point to the right places.
Here's some documentation on the build events: https://learn.microsoft.com/en-us/visualstudio/ide/how-to-specify-build-events-csharp
Here's some (crappy) documentation on the Build Events properties page: https://learn.microsoft.com/en-us/visualstudio/ide/reference/build-events-page-project-designer-csharp
Here's some (useful) documentation on the macros: https://msdn.microsoft.com/en-us/library/c02as0cs.aspx
Have a look at the Properties of your dependencies and set "Local Copy" for your exe, this should copy the exe to your A.exe's bin folder.
Edit:
It's the german version, but should look like this:
You can use the Post-build events ( Project properties -> Build Events ) to copy the file at the end of build.

How to use NUnit 3 in VS2015RC

Is it possible to use NUnit3 Beta in VS2015RC?
I've just created a new Library Project (Package) and added NUnit and created a simple test to show the errors I'm getting.
Does it have some dependency on an older version of the framework?
project.json
Test Class
Update
The Release Notes say:
To work around this issue, follow these steps: Right-click the project
in which the errors are reported in Solution Explorer, and then click
Unload Project. Right-click again on the project in Solution Explorer,
and then click Edit .
Note In this command, represents the actual project
name. In the entry at the top of the project file that
has no Condition attribute, add the following:
true
Save and close the file. Right-click the project name in Solution
Explorer, and then click Reload Project.
However I cannot get this to work, I just get more warnings and errors in my errors window.
It is very likely that you should use xUnit.net for now,
https://github.com/aspnet/Testing/issues/34
NUnit won't be ported unless someone steps in.

Running multiple NUnit Projects in Visual Studio

I have a solution that has multiple projects including NUnit Test projects. So the solution looks like this (using generic names, these aren't the actual names):
+ Solution
+ Project1
+ Project1.Test
+ Project2
+ Project2.Test
+ Project3
+ Project3.Test
...
I would like to run all the NUnit Tests through the NUnit GUI or console application when I click 'Start Debugging' from within Visual Studio.
Right now, what I have done is added a new Class library called TestRunner and set it to be the StartUp project (I've read I don't really need to do this, I can just right click on the project and click 'Debug > Start new instance'). Then inside the project properties on the Debug page, I set the 'Start Action' to 'Start external program' and select the nunit-console.exe (Looks like nunit.exe GUI doesnt support multiple assemblies as input parameters). Then in the 'Command line arguments' I enter the path to each of the projects. Like this:
This seems to work OK, but I'm wondering if there is a better way to do this (maybe I don't need an extra project, or there might be an easier way to run multiple NUnit Test projects from within Visual Studio).
Any suggestions on improving this would be appreciated.
Running NUnit 2.5.9 and Visual Studio 2008.
There are various test runner extensions for Visual Studio itself - personally I use ReSharper (commercial) and also NCrunch (used to be free, now commercial), although the latter is more of a continuous test tool than a "run explicitly" tool. If you're using Visual Studio non-Express, you should really look at running tests integrated into the IDE - it's much, much nicer than switching between apps.
However, if you want to run the NUnit GUI, just set up an NUnit project configuration which includes all your test projects - you'll only need to do that once, then you can use it however you run the tests.

Best practice for using test files/directory in Visual Studio 2010 C# test projects

I have a test project in a Visual Studio 2010 solution, which tests another project that is an FTP utility. The test project needs to FTP files here and there, so I use a test file to pass to the utilities methods and verify it gets uploaded/archived/etc. In my test project I have a folder under the root of it called TestFiles, with a single .txt file in it. I want to have it to where whenever someone checks out the solution from source control and runs the unit tests, that the file in that folder is grabbed and used in the FTP unit tests.
I've tried using this, and variations in the post-build event command line, but with no luck:
copy $(ProjectDir)TestFiles\Test.txt $(ProjectDir)Debug\bin\Test.txt
All I really want to do is make sure that I can use a relative path for any local test files, so that I am guaranteed not to have problems no matter where someone on my team checks the project out to (or if Team Foundation Server runs an automated build and fires the unit tests for my project).
I'm currently trying to access the file in my unit tests like this, so that I just grab it from the debug area:
ftp.uploadThisFileSomewhere(
AppDomain.CurrentDomain.BaseDirectory + "\\TestFiles\\Test.txt");
So, is this the proper way to grab a test file? I don't think it is, but I can't seem to find a good best practices doc on it. If it's good enough, how do you copy/guarantee a relative location no matter where the project is built/run?
The suggested practice is to use DeploymentItem Attribute for each item that needs to be autocopied during the MSTest process.
There's a number of steps to follow, from defining the items, to making sure each file has the correct properties, blah blah blah. So, I wrote a nice lit of instructions about how to do this.
Have a read of a detailed description about how to do this.
You can use DeploymentItemAttribute, http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute(v=VS.90).aspx.
Include the file in your project and set it's properties to Content and Copy If Newer. It will be copied to to the build/run directory at both debug and release.
Hi I have got same problem and I used Resources. I created TestFiles.resx in my test project, next I added files. And in test units I used for example TestFiles.SomeFile and I was able to forget about paths etc

Categories