Replies: 5 comments 2 replies
-
This is an interesting scenario and it is definitely possible, but not so easy to explain all the details. Maybe you can achieve this with a plugin, but plugins can influence the behavior and they don't give you real control on how the test is executed. In case of Reqnroll, the tests are executed by the test runners (MsTest, NUnit, xUnit), so basically if you want to embed a Reqnroll test execution inside your app, you would need to do the same things what they do. (BTW, you can check the verify plugin to see an example of using the So instead of a plugin, I would recommend the following approach. In Reqnroll the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback and I've come to your conclusion too that its going to be tricky but possible. I've been able to extract all available steps and scenario classes through reflection however I also need to extract the location, title and description. That information is unfortunately not directly accessible through reflection without running the test as its generated in
So I figured, I could just extend the NUnit Generator and add a custom attribute to the method and then extract that information from there. How hard can it be? (Famous last words). (Other option would be trying to parse the IL but yeah lets avoid that :)) So I created a plugin according to the docs like the following and I'm hoping I can omit some stuff by directly extending
and:
I saw that the out of the box generators are registered in So after building the plugin I placed it in the folder containing my bdd tests .csproj file. When I now build, I receive the following exception: StacktraceThe "GenerateFeatureFileCodeBehindTask" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) at Reqnroll.Generator.Plugins.GeneratorPluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor) at Reqnroll.Generator.GeneratorContainerBuilder.LoadPlugins(ObjectContainer container, GeneratorPluginEvents generatorPluginEvents, UnitTestProviderConfiguration unitTestProviderConfiguration, IEnumerable`1 generatorPlugins) at Reqnroll.Generator.GeneratorContainerBuilder.CreateContainer(ReqnrollConfigurationHolder configurationHolder, ProjectSettings projectSettings, IEnumerable`1 generatorPluginInfos, IObjectContainer parentObjectContainer) at Reqnroll.Tools.MsBuild.Generation.WrappedGeneratorContainerBuilder.BuildGeneratorContainer(ReqnrollConfigurationHolder reqnrollConfigurationHolder, ProjectSettings projectSettings, IReadOnlyCollection`1 generatorPluginInfos, IObjectContainer rootObjectContainer) at Reqnroll.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTaskExecutor.Execute() at Reqnroll.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()WRN: Assembly binding logging is turned OFF. So that is where I'm stuck with trying to extract data. In the meantime I'm working on getting the |
Beta Was this translation helpful? Give feedback.
-
Okay I got the code generator plugin to work. Three take aways:
Now my next step is to wire up the test runner. |
Beta Was this translation helpful? Give feedback.
-
I've made a little bit of progress but now stuck on the dependency injection. However I'm able to get all scenarios, all steps, start a scenario and get the result out of scenario. This all is integrated in our Blazor application: So far this is what I did:
It looks like this:
So far so good. I can load the assembly, start it and get the result out it too ( Right now I'm having some trouble trying to resolve services provided by my main application. So far I've tried the following thought neither of them work. Open to suggestions / pointers... A: I've tried adding the directly to the feature / testthreadcontext (scenario seems to be null?)
B: I tried registering them during the binding discovery:
C: I tried adding them to the global container created in 4
|
Beta Was this translation helpful? Give feedback.
-
I've been confused where the I've now gone via the ugly static singleton shared IServiceProvider route instead to wire up my services but would like to investigate this further. I couldnt quite exactly find where the binding classes are instantiated. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm trying to write a plugin or an app to manually start a scenario and step through each step one by one (kinda like a debugger). The reason I would want to load the scenario into my existing app is to re-use services without having to provide mocks for them. We have a physical robot and machines that integrate with this app over an OPCUA interface. For some actions, an operator interaction is required (eg Feed in item, take out processed item).
I was thinking if I would be able to do something like this:
Another reason for this integration is for training an operator (eg we can setup an scenario and step through to train the operator how to handle it).
I found the plugin documentation however I think its quite bare and not really clear outside of some small config / DI to have any other effect on the test execution.
I was wondering how to hook into RuntimePluginTestExecutionLifecycleEvents.cs (BeforeStep & AfterStep)
Beta Was this translation helpful? Give feedback.
All reactions