ttutisani/Xunit.Gherkin.Quick

Has anyone got it work in a Unity3d project? - HelpWanted

Enough7 opened this issue ยท 14 comments

Unfortunately Unity autogenerates the .csproj files so any changes get overwritten. I wonder does anybody know how to get this work?

Changes that are in the csproj file of the test project include references to the Nuget packages and "copy to output directory" setting for the .feature files. I can't think of anything else that is in the csproj file and thus can be lost during overwriting process. Can you please confirm that I understood the problem correctly?

If so, perhaps one way would be to keep the test project outside of the unity IDE. After all, the test project needs to reference your other projects and not the other way around. And you can execute the tests via command line or via visual studio (opening the test project from the visual studio directly instead of double-clicking it from inside the unity IDE). Does this help?

I don't have the unity IDE installed at the moment on my machine, so I cannot suggest anything else myself. I hope others can help.

The problem basically is that I can not use my .csproj file because unity manages it. Unity offers only a Assembly definition file .asmdef which one can manipulate. I got a Xunit-Test running, but the feature test does not work. Its said in the readme the filename does not matter maybe I should change the file extension from .feature to .cs so the Testrunner compiles it.

If you change it to .cs, it won't compile because the content is not c#, it's gherkin. So, no, don't change it.

From what you described, it compiles but does not find feature tests (scenarios) to run. Does it allow to mark the feature file as a content, or to copy to the output directory? Can you check if the feature files are actually in the output directory? Basically, goal is to get those files into the test output directory. For clarity, when test executes from visual studio, the compiler puts everything in the output directory (dll files, exe files, and even feature files since they need to be marked as for output - this is mentioned in the readme of Xunit.Gherkin.Quick).

So, once the feature file is in the output directory, you need to see where it is, and specify the path to it correctly via the FeatureFile attribute that you attach on top of the Feature class with steps.

I am probably to much of a C#-newbe to find that out ๐Ÿ˜ข

ยฏ\_(ใƒ„)_/ยฏ

Let's keep this issue ticket open. Maybe somebody else has already used Xunit.Gherkin.Quick with Unity and can provide a detailed answer.

Someone told me to use Directory.Build.props to add an ItemGroup to the generated files

Did that work out well?

Did that work out well?

No it did not ... unfortunately. At least for me.

My new approach is to write a class library and import it into unity. I got the example in the ReadMe up and running with TargetFramework netcoreapp3.1. Unfortunately unity does not support netcore only netframework 2 or 4. So I tried to get the example running in netframework 4.2 but I failed. Am I missing something is netframework different from net as it says in the ReadMe I thought it's the "same".

.NET framework is a windows-only framework, while .NET Core is a cross-platform framework.

Are your tests discovered fine? If they are not discovered, then maybe it's a known issue (I will describe below). If the tests are discovered fine, but you get another kind of error/exception, please provide more details.

About the known issue: I found this issue that describes the issue with the full .net framework. Honestly, I have not checked since then if the issue is resolved. Maybe that's what you are facing. In short, there was a bug found in the Xunit framework (on which Xunit.Gherkin.Quick depends) that it does not discover tests properly with the .NET framework. As you can see in the referenced issue, I opened the ticket in the Xunit GitHub repository, and that ticket is still open. However, they claimed in that ticket they fixed the issue with v3. As I said, I have not checked if the issue is fixed now. But I think this is the same issue that you are facing.

I use Jetbrains Rider-IDE. It has a GUI for UnitTests.
Screenshot (219) I press the Play button below the hammer icon. But than the tests just disappear in the UnitTestExplorer:
Screenshot (218)
That happened before when in my core-try - project the feature-file-attribute had a invalid path. Thank you about the .Net lesson much appreciated :)

Status: I got it up and running. I set the TargetFramework in my Tests.csproj to netcoreapp3.1 and in my NetCoreExample.csproj I set the TargetFramework to netstandard2.0. I packed a NuGet-Package extracted the .dll from it and imported it in my unity-project. It seems like it works.

Very good. Please close this issue as a confirmation that your issue is resolved.

Thank you for reporting both the problem and the solution too! It will help others and myself.

I was not sure. My issue is solved but the issue making it work in unity not, but I guess it is the best solution right now