Specflow: appSetting.Json is not getting copied to SpeclowPlusRunner Folder

Created on 18 Jul 2019  Â·  9Comments  Â·  Source: SpecFlowOSS/SpecFlow


appSetting.Json is not getting copied to SpeclowPlusRunner Folder

SpecFlow Version:

  • [x] 3.0
  • [ ] 2.4
  • [ ] 2.3
  • [ ] 2.2
  • [ ] 2.1
  • [ ] 2.0
  • [ ] 1.9

Used Test Runner

  • [x] SpecFlow+Runner
  • [ ] MSTest
  • [ ] NUnit
  • [ ] Xunit


Version number: 3.0.352

Project Format of the SpecFlow project

  • [ ] Classic project format using packages.config
  • [ ] Classic project format using <PackageReference> tags
  • [x] Sdk-style project format

.feature.cs files are generated using

  • [x] SpecFlow.Tools.MsBuild.Generation NuGet package
  • [ ] SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • [x] VS 2019
  • [ ] VS 2017
  • [ ] VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • [ ] Enabled
  • [ ] Disabled

Are the latest Visual Studio updates installed?

  • [x] Yes
  • [ ] No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Framework:

  • [ ] >= .NET 4.5
  • [ ] before .NET 4.5
  • [ ] .NET Core 2.0
  • [ ] .NET Core 2.1
  • [x] .NET Core 2.2
  • [ ] .NET Core 3.0

Test Execution Method:

  • [x] Visual Studio Test Explorer
  • [ ] TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • [ ] Command line – PLEASE SPECIFY THE FULL COMMAND LINE

<SpecFlow> Section in app.config or content of specflow.json


Repro Project

Issue Description


WHile I Build the project, appsetting.json file is not getting copied into SpecflowPlusRunner folder. Hence test wont get run which are dependent on this json file.

Steps to Reproduce

SpecFlow+

Most helpful comment

@SabotageAndi I have encountered this issue as well. I've set up a small sample repo at https://github.com/tparikka/SpecFlowRunnerPlusAppSettingsIssue that you can download and run that shows the problem. The issue is that content like app settings files need to exist in the same directory as the binary executes from. Items like appsettings are copied to %projectroot%\bin\Debug\netcoreapp3.1 but NOT to %projectroot%\bin\Debug\netcoreapp3.1\SpecFlowPlusRunner\netcoreapp3.1.

All 9 comments

I cant make it work with Pre and Post build because I am running my Test Cases in a Docker Container inside a Linux machine.
SInce Linux has different slash culture than windows for defining path, I am not able to find a solution which works for both Environment.
FOr now I have written a COpy command inside Docker file to copy json file from Bin to SPecFLow folder

Why do you need the appsettings.json file in the SpecFlowPlusRunner folder? Should it not be in the folder of the test assembly?

While running the tests through SpecRun, code which requires appsetting.json wont be executed as it try to find the json file in SpecFlowPlusRunner folder and it wont be available there if not placed explicitly.

When it doesnt find the json file inside SpecRunner folder it gives an error which says cannot find appsetting.json

Could you create a small project where we can reproduce the issue? This would help us to analyse this issue.

@SabotageAndi I have encountered this issue as well. I've set up a small sample repo at https://github.com/tparikka/SpecFlowRunnerPlusAppSettingsIssue that you can download and run that shows the problem. The issue is that content like app settings files need to exist in the same directory as the binary executes from. Items like appsettings are copied to %projectroot%\bin\Debug\netcoreapp3.1 but NOT to %projectroot%\bin\Debug\netcoreapp3.1\SpecFlowPlusRunner\netcoreapp3.1.

I had a look at this issue in the last days.
The issue exists, if you are using the Process test thread isolation. In SharedAppDomain this works.
The reason is that for the process isolation, we have a separate binary that is in its own folder. We have to set the working directory to this folder, because of .NET Core assembly loading.

So you can't simply say "appsettings.json" in accessing the file. We provide an API to get the folder where the test assembly is. It's in the TestRunContext (https://specflow.org/plus/documentation/TestRunContext/) class.

I adjusted our ASP.NET Core example (https://github.com/SpecFlowOSS/SpecFlow-Examples/tree/master/ASP.NET-MVC/BookShop) as an example of how you can use it.
There we use the ConfigurationBuilder. It is here: https://github.com/SpecFlowOSS/SpecFlow-Examples/blob/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests/Hooks/Hooks.cs#L26

@tparikka & @zeeshankhan0330 it this information unblocking you?

Thanks !!

On Fri, Feb 21, 2020, 8:24 PM Andreas Willich notifications@github.com
wrote:

I had a look at this issue in the last days.
The issue exists, if you are using the Process test thread isolation. In
SharedAppDomain this works.
The reason is that for the process isolation, we have a separate binary
that is in its own folder. We have to set the working directory to this
folder, because of .NET Core assembly loading.

So you can't simply say "appsettings.json" in accessing the file. We
provide an API to get the folder where the test assembly is. It's in the
TestRunContext (https://specflow.org/plus/documentation/TestRunContext/)
class.

I adjusted our ASP.NET Core example (
https://github.com/SpecFlowOSS/SpecFlow-Examples/tree/master/ASP.NET-MVC/BookShop)
as an example of how you can use it.
There we use the ConfigurationBuilder. It is here:
https://github.com/SpecFlowOSS/SpecFlow-Examples/blob/master/ASP.NET-MVC/BookShop/BookShop.AcceptanceTests/Hooks/Hooks.cs#L26

@tparikka https://github.com/tparikka & @zeeshankhan0330
https://github.com/zeeshankhan0330 it this information unblocking you?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/SpecFlowOSS/SpecFlow/issues/1668?email_source=notifications&email_token=AEOYUKKLBXZWFG5HOIAS4P3RD7TLTA5CNFSM4IE2AYP2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMS6URA#issuecomment-589687364,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEOYUKITEV6PKBTQOK2MZELRD7TLTANCNFSM4IE2AYPQ
.

Because of inactivity and I think I have answered it, I am closing this issue.
Please open a new issue if necessary.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings