Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

.NET Core unit tests for project build as exe
piotr_s
#1 Posted : Tuesday, October 1, 2024 1:03:23 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/24/2017(UTC)
Posts: 4
Location: Poland

Hi,
I've project A configured as Windows application (exe). Unit test project B is using reference for project A. In .NET Core Windows application project are build as two file .dll and .exe. Output folder of test project B contains these two files, but workspace folder used by NCrunch contains only .dll file from A project.
My unit tests based on existence of this .exe file, so all test are "red". In Visual Studio Tests Explorer all test are "green", only NCrunch has problem.
Is there any possibility to configure NCrunch to copy both files, exe and dll to the workspace folder. I want to avoid passing file path to the exe file in "additional files to include".
Remco
#2 Posted : Tuesday, October 1, 2024 11:43:43 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,135

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for posting.

The .EXE file you are referring to is just a shim that invokes the runtime to load the .DLL. Because it doesn't form part of the normal dependency structure of the solution, the 'Copy referenced assemblies to workspace' setting won't automatically copy it to the test project's output directory.

I don't believe this EXE file changes as your software does, so it might be possible to simply set it up a copy of it as a resource file in your test project that can be copied to the output directory on build (i.e. basically a copy local content file).

If you can share any more detail about why you need this file in your test, I might be able to help with providing a more suitable workaround.
piotr_s
#3 Posted : Wednesday, October 2, 2024 11:14:46 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/24/2017(UTC)
Posts: 4
Location: Poland

Hi,
this .exe file is used to execute some action, which result is checked by unit test assertions. I could add this exe file as a resource, but if I change build configuration, the exe file won't change and won't be able to use corresponding dll file.
Remco
#4 Posted : Wednesday, October 2, 2024 11:18:06 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,135

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
My understanding of this .EXE file is that it functions in the same way as calling dotnet.exe with your DLL.

If you use dotnet.exe (usually under C:\Program Files\dotnet) to call the DLL instead of calling the .EXE directly, it should be possible to run the code without requiring it.

Another option could be to use the methods available on the NCrunchEnvironment class to find the workspace that contains the stub .EXE, and copy it over manually as part of your test code.
piotr_s
#5 Posted : Monday, October 7, 2024 7:15:17 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/24/2017(UTC)
Posts: 4
Location: Poland

In my opinion, instead of necessity to write additional code to copy .exe file or linking it as resource, NCrunch should know that if the project is configured as windows application (console or desktop), there are two files .exe and .dll and these two files should be copied to the NCrunch working directory.
Remco
#6 Posted : Monday, October 7, 2024 11:30:03 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,135

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
piotr_s;17649 wrote:
In my opinion, instead of necessity to write additional code to copy .exe file or linking it as resource, NCrunch should know that if the project is configured as windows application (console or desktop), there are two files .exe and .dll and these two files should be copied to the NCrunch working directory.


Agreed. I've noted this down for review. I was just hoping to help you work around this limitation until I could make a fix available.
piotr_s
#7 Posted : Tuesday, October 8, 2024 6:19:22 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 2/24/2017(UTC)
Posts: 4
Location: Poland

I appreciate you help. It would be great if NCrunch would have such a functionality (maybe not turned of by default, it could be configurable).
Remco
#8 Posted : Tuesday, October 8, 2024 6:50:13 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,135

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
piotr_s;17655 wrote:
I appreciate you help. It would be great if NCrunch would have such a functionality (maybe not turned of by default, it could be configurable).


No need to configure. We have enough settings already. It should just happen, like the other files in the workspace.

I think the reason it's not happening already is because the .EXE shim must be getting generated through a separate build step that will require special handling.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.060 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download