Replies: 1 comment 1 reply
-
This question is quite old and unfortunately not answered. The OP has probably moved on, but here is a brief answer for anyone who comes across this. EventListeners are kept separate from tests by design. Under the .NET Framework, they run in a separate AppDomain. By default, when using the console runner, they are even in a separate process. In addition, they are normally handled asynchronously, while the tests themselves continue. As noted by the OP this is independent of the versions used. There is a reason for these limitations. A runner may be listening to multiple sets of tests running in parallel, either in separate processes or different threads in the same process. In future, they may even be in separate machines. So all the information available to a listener must be contained in the event it receives. In some cases (i.e. for some events) it's possible to include extra information in the packet that is sent to the listener. But that would require a bit more information in order to give advice here. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I implemented a custom test event listener (by using the ITestEventListener extension point). So far it works well, the event listener is loaded and the events are triggered as expected.
However, I observed that I cannot use static types in both the event listener and the test libraries. I also observed that for net47 target, the test case and the event listener run in different appdomains and i guess thats the root cause (its well-known that its not possible to share static instances across appdomains).
I run the tests with vstest + test adapter or with dotnet test.
Running the same test in ReSharper works fine because ReSharper uses the same appdomain for both the test and the custom event listener, but has also a self-implemented test adapter with probably some magic inside.
Is there any way to overcome that my custom eventlistener is loaded into a separate appdomain?
Unfortunately I still have to target net47.
Thanks and best regards!
I use
nunit 3.11
nunit.engine 3.9
nunit3 test adapter 3.13
but it seems pretty much independent from the concrete versions.
Beta Was this translation helpful? Give feedback.
All reactions