How to run tests under a specific folder with NUnit 3? - nunit

I have a lot of tests (classes) and they are placed to different folders.
It looks like this:
I want to run all the tests under a specific folder including all sub-folders.
Please help me to do it using NUnit 3 console commands.
Here is a manual for this https://github.com/nunit/docs/wiki/Test-Selection-Language
The thing is: if I use: --where "test==LottoSend.com.TestCases.BackOffice" then it runs only tests under sub-folders in BackOffice folder (CMS, Packages, Raffle, etc.) but it doesn't run tests placed directly in "BackOffice" folder (such as BlackListTests.cs etc.)
Maybe I need to use another parameter for this?

NUnit knows nothing about the location of your source code. It doesn't look need or look at source code at all, but at the compiled test assembly.
If it's running the tests in the BackOffice folder, it's because they are all defined in the namespace "LottoSend.com.TestCases.BackOffice" - not because of what folder they are in.
What namespaces are used in your subfolders? Common practice would put the code under CMS in "LottoSend.com.TestCases.BackOffice.CMS" but it's up to you how you write the code.
So your choice is to either change the namespaces to match the folders or move the code to a folder that matches the namespace.

Related

VSCode: how to structure a simple python package with few modules and tests, debugging and linting?

I'm having more trouble than I'd like to admit to structure a simple project in Python to develop using Visual Studio Code.
How should I structure in my file system a project that is a simple Python package with a few modules? Just a bunch of *.py files together. My requisites are:
I must be able to step debug it in vscode.
It has a bunch of unit tests using pytest.
I can select to debug a specific test from vscode tab and it must stop in breakpoints.
pylint must not show any false positives.
The test files must be in a different directory of the main module files.
I must be able to run all the tests from the console.
The module is executed inside a virtual environment using python standard lib module venv
The code will use type hints
I may use another linter, even another test framework.
Nothing fancy, but I'm really having trouble to get it right. I want to know:
How should I organize my subdirectory: a folder with the main files and a sibling folder with the tests? Or a subfolder with the code and a subsubfolder with the tests?
Which dirs must have a init.py file?
How the tests should import the files from the module? Should I use relative imports?
Should I create a pytest.ini file?
Should I create a .env file?
What's the content of my launch.json the debugger file config in vscode?
Common dir structure:
app
__init__.py
yourappcode.py
tests (pytest looks for this)
__init__.py
test_yourunittests.py
server.py if you have one
.env
.coveragerc
README.md
Pipfile
.gitignore
pyproject.toml if you want
.vscode (helpful)
launch.json
settings.json
Or you could do one better. Ignore my structure and look at the some of famous python projects github page. Like fastAPI, Flask, asgi, aiohttp are some that I can think of right now
Also:
I think absolute imports are easier to work with compared to relative imports, I could be wrong though
vscode is able to use pytest. Make sure you have a testing extension. Vscode has a built in one im pretty sure. You can configure it to pytest and specify your test dir. You can also run your test from command line. If youre at the root, just running ‘pytest’ will recognise your tests dir if it’s named that by default. Also your actual test files need to start with prefix test_ i think.
The launch.json doesn’t need to be anything special. When you click on the settings button next to play button in the debug panel. Vscode will ask what kind of app is it. I.e If its a flask app, select python then select flask and it will auto generate a settings file which you can tweak however you want in order to get your app to run. I.e maybe you want to expose a different port or the commands to run your app are different
It sounds to me like you just need to spend a bit of time configuring vscode to your specific python needs. For example, you can use a virtualenv and linting in whichever way you want. You just need to have a settings.json file in the .vscode folder in your repo where you specify your settings. Configurations to specify python virtualenv and linting methods can be found online

Any dynamic way to use "using" statement in PowerShell?

I'm having issues with the using statement which can be seen here. This statement (unlike Import-Module) is required in order to get an actual class definition from a PowerShell module. I have a use case for this because I need the class definition itself for Pester unit testing.
The problem is I can't find any way to provide the module path dynamically. I'm unable to use variables like $PSScriptPath in the path. I'm only able to provide it with a absolute path or a relative path. Neither of these really work for me.
Absolute path: Issue here is unit tests will be run on different machines (build servers). Therefore, having a hardcoded absolute path from a dev machine isn't an option.
Relative path: This also is problematic, since unit tests are triggered from a base directory which then run all Test files recursively. So I would have to Set-Location to specific directories for each test in order for relative paths to function. To tests dozens of modules, this is a lot of overhead to have to manage when I should be able to just run all my unit tests without this hassle.
Is there a better way I can manage this? General directory structure is like this...
src
project1
someModule1
someModule1.psm1
someModule2
someModule2.psm1
someModule3
someModule3.psm1
tests
someModule1.Tests.ps1
someModule2.Tests.ps1
someModule3.Tests.ps1
From src directory, run Invoke-Pester -Script . to run all unit test files. The "Tests" files need to be able to import classes from their corresponding modules. Worse yet, I'm not getting any errors when the using statement doesn't find the module path unless I run the using statement interactively in the console. Any ideas?
Are the modules installed properly in a PSmodule path?
Are the modules installed. If so you can get the path to them by querying:
(Get-Module -Name someModulex -ListAvailable).ModuleBase

Octopus Package Application Step in TFS Build not picking up files in sub folders

Hi I am using Octopus Deploy Package Application step to package up my website
I specified the Source Path, Output path etc just fine.
If I do not specify the Include files it brings back everything in the folder structure as the package. But I only want to Package certain things like the CSS, views, dll's etc
If i Specify an include form a sub folderlike /bin/.dll it does not bring the files through, even though this is the exact example they give on the more info icon. but if i specify something in the root like .png which is not in a subfolder it works fine.
Anyone faced this issue. Please see image below to see the step setup
Use the path below, you'll get all dlls in bin folders:
**/bin/*.dll

Using a variable like $(ProjectDir) in Integration Services Package (.dtsx)

Is this possible?
I have a package that needs to be copied to three 3 different servers. Each server is used for a different testing environment. All three servers have the same directory layout. The layout is as follows:
*\SERVER\ConfigFiles* <- Here go the .dtsConfig files.
*\SERVER\Packages* <- Here go the .dtsx files.
I want to be able to use the same package copied over the three 3 different servers without any modification. The only difference amongst the 3 servers would be the content inside the .dtsConfig file. The config files contain directories for the excel, log, and SQL server connection for each environment.
For example. Let's say I have a package called Cars.dtsx. This package is EXACTLY the same amongst all three servers. The package file points to a .dtsConfig file that is in the ConfigFiles folder (which is found on all three servers). I want a way for the package to point to the ConfigFiles\Cars.dtsConfig file on each server, but I want to do it without having to provide the name of the server in the directory.
The way I tried it is using "$(ProjectDir)..\ConfigFiles\Cars.dtsConfig" which seems to work if I run the package through the .sln file rather than the .dtsx file.
I hope that wasn't too confusing. Let me know if you need anymore info. Thanks.
Unless I'm missing some nuance, you don't need to do anything special.
Your package is going to have a hard coded reference to D:\ConfigFiles\Cars.dtsConfig It won't matter whether that package is being run from ServerA, ServerB or ServerZ (as long as you have the same file structure on those servers).
By virtue of your asking the question, are you experiencing something different?

Environment.CurrentDirectory with NUnit GUI differs to the TeamCity value, how can I sync them?

As above really, I have some integration tests that use files from a relative file path. To help picture it here is the file structure:
/Dependencies
/VideoTests/bin/release/video.dll
/SearchTests/bin/release/search.dll
/OtherProjects
The GUI is running the tests from the root, however when TeamCity runs the tests it is running the tests from each test dlls bin directory. Now I don't mind which one I can get to follow the other but I do need them to be the same otherwise my relative paths just won't work!
Any ideas?
P.S. Using TeamCity 5.0 and NUnit 2.5.
You probably don't want to rely on CurrentDirectory. I'd suggest reading the doc, but the main point you'll want to take away is that the CurrentDirectory is where the .exe was started from: it could be any path in the system. For example, let's assume your users add your .exe (or whatever .exe uses your DLLs) to their path. They could then navigate to c:\foo\bar and start the .exe from there, which would set the CurrentDirectory to "C:\foo\bar" and you may not be able to deal with that.
I think it would be preferable for you to rework whatever you're doing so you don't rely on CurrentDirectory. What problems are you encountering by relying on CurrentDirectory right now?
Have you made sure that both TeamCity and NUnit are using the same working directory when starting the application?
And if they aren't, you could adjust the current directory in the test code.