For Machine.Specifications suites, is there a way to run code globally? - mspec

I'd like to execute startup/teardown code one time for all discovered specs when using Mspec. Does it currently have any facility for doing this?

IAssemblyContext is your friend. But it does that per assembly, not globally.

Related

How to set outcome of XUnit test

Can you manually set outcome of test using XUnit? In one of my test I have to fulfill prerequisite and if it fails I need to set outcome of test to inconclusive. In NUnit you can set outcome by Assert.Inconclusive(), Assert.Fail(), etc. Am I able to do something similar with XUnit? Is there some best practice how to do this?
There is no out-of-the-box way of doing what you want in xUnit. See https://xunit.github.io/docs/comparisons.html for more information.
However Assert.Fail("This test is failing") can be replicated using Assert.True(false, "This test is failing").
The closest equivalent of Assert.Inconclusive in XUnit would be the use of the Skip attribute. But as far as I can see, there is no way to invoke this part way through a method, like you can with NUnit's Assert.Inconclusive.
Someone did write an Assert.Skip method for v1.9 here: https://github.com/xunit/xunit/blob/v1/samples/AssertExamples/DynamicSkipExample.cs, however it no longer compiles in v.2.2.0. Actually the xUnit authors seem to be antagonistic to inconclusive tests (https://xunit.codeplex.com/workitem/9691).
I think you can use Assume.That in your munitions test method it won't work while setup but you will to use that in test method.

Is it possible to run hashtab.dll in standalone mode?

This is my first post and I hope I am posting in the right section. I would like to know if it is possible to execute a dll file (here, hashtab.dll) as if it's a standalone application. Tried using dependency walker, but I have no idea of interpreting the results and the errors. Only if I can do that, I'll be able to use rundll.exe to execute the function. Any ideas on how to get this done?

Existing solutions to test a NSIS script

Does anyone know of an existing solution to help write tests for a NSIS script?
The motivation is the benefit of knowing whether modifying an existing installation script breaks it or has undesired side effects.
Unfortunately, I think the answer to your question depends at least partially on what you need to verify.
If all you are worried about is that the installation copies the right file(s) to the right places, sets the correct registry information etc., then almost any unit testing tool would probably meet your needs. I'd probably use something like RSpec2, or Cucumber, but that's because I am somewhat familiar with Ruby and like the fact that it would be an xcopy deployment if the scripts needed to be run on another machine. I also like the idea of using a BDD-based solution because the use of a domain-specific language that is very close to readable text would mean that others could more easily understand, and if necessary modify, the test specification when necessary.
If, however you are concerned about the user experience (what progress messages are shown, etc.) then I'm not sure that the tests you would need could be as easily expressed... or at least not without a certain level of pain.
Good Luck! Don't forget to let other people here know when/if you find a solution you like.
Check out Pavonis.
With Pavonis you can compile your NSIS script and get the output of any errors and warnings.
Another solution would be AutoIT.
You can compile your install using Jenkins and the NSIS command line compiler, set up an AutoIT test script and have Jenkins run the test.

How to run tests conditionally in NUNIT?

I'd like to be able to set a condition from which to decide whether certain tests run in NUNIT.
For example if a global variable x = 1 then only run the tests from a certain class/assembly or only run the first test.
Is anything like this possible?
How would one go about doing this?
Thanks!!
I would recommend using Categories with your NUnit tests. This would allow you to run groups of them at a time, or all at once.
While Categories seem like the "more pure" way to do this, you could programmatically skip tests like this post asks: Programmatically skip an nunit test. It seems to me, this approach is what you're looking for though.

Build if then statements at run time?

My product owner has asked me to make some comparision logic configurable so the process engineers can change things without making code changes. Currently the code is a SELECT CASE statement with various IF THEN statements that are fairly standard. The problem I can't seem to find a way around is that he wants through configuration to AND/OR a variable number of comparisons in the IF THEN statements. His idea is the that the configuration would work like a limited query builder for the process engineers. The only solution I've come up with is to build a function in a string and use the VBCodeProvider to compile it at runtime. Is there a better way to approach this?
One way to do it is just store the booleans in your configuration file, load them up at run time, and use them in your code like any other boolean.
A better way would be to have the configuration as close to his problem domain as possible, then code up the proper booleans from those to use in your code.
You could use expressions to accomplish this. With this you would be able to build up an IfExpression and build up its conditions. You would be able to compile this and run it all at runtime.