xUnit framework: Equivalent of [TestFixtureSetUp] of NUnit in XUnit? - nunit

What is xUnit's equivalent of NUnit's [TestFixtureSetUp]?
We have explored and found that IUseFixture<T> is the equivalent of [TestFixtureSetUp], but it's not working as expected.
As we have explored (in case of NUnit), we found that [TestFixtureSetUp] marked methods for code to be executed only once before all test in the fixture have been run. In xUnit, the equivalent of [TestFixtureSetUp] is IUseFixture<T> as we have explored, but during testing, we found that the SetFixture method of IUseFixture is being called before every test (not only once for all methods).
Please let us know how can we achieve the above in xUnit. Also correct us if we are misunderstanding something. Thanks.

There is no direct equivalent of [TestFixtureSetUp] in XUnit, but you can achieve similar functionality. This page lays out the translation between NUnit and XUnit (as well as a couple other C#/.NET test frameworks). However, XUnit largely got rid of setups/teardowns (this article explains why that decision was made). Instead, you need the test suite to implement an interface called IUseFixture<T> which can initialize some data for the fixture.
You might also want to read this overview of XUnit, written from the perspective somebody coming from an NUnit/MbUnit background.

Related

Is there a nunit setup attribute equivalent that could be added for some tests in xunit?

In NUnit when I had to do the setup for some tests I would use [Setup] Attribute.
Now in xUnit there are TextFixtures but they are only run before each test or run before all tests once, but there's no option to run it for some but not all tests.
This question is purely for my personal educational purposes.
Above can be easily solved by simply making a SetUp() method and just calling it inside the tests where it is needed, but I was wondering if there was a 'proper' way to do this.

How to do beforeAll in Swift Quick Nimble

In Jasmine, the beforeAll() block can be used within a describe and run before all of the it blocks within that describe. Is there something equivalent to this in the Quick/Nimble BDD framework in XCUITest (xcode) in Swift? I could only find the beforeSuite() but that is ran before all describe blocks.
Currently, Quick does not support beforeAll / afterAll.
You can read more on the reasons behind this decision in this issue. But the short answer is it is not currently supported and they have no plans to add them in the near future.
You should be able to go around this using the other options supported: beforeSuite, afterSuite, beforeEach and afterEach.

What is the differences between code injection and sub-classing in Java

I was reading about code-injection at run-time and there are many tools/APIs available like Javassist, GluonJ and AspectJ which provide features to inject code. However, I did not understand purpose for injecting code at run-time while we can do override behaviors by sub-classing in Java. With Javassist and GluonJ, I can create classes at run-time but why does anyone do that, in the first place? Can anyone please help me to understand the difference and purpose of code injection ?
Code injection is usually used into application that are used to modify/check/trace other software. In Java we usually reffer to this kind of library as Bytecode modification libraries so if you look on the internet you will probably find more information under this name.
Here I listed a couple of examples of big and famous projects that I now are using Bytecode modification into their cores:
Evosuite: this project takes an application in input and generates unit test for it. Code injection is used to explore the desired project and dependencies and traceability
JaCoCO: this project is a tool for Java project. It is supposed to be attached to your application and once you run your JUnit tests it is going to generate a report on the coverage achieved. Obviously here code injection is necessary to trace every method call made during test execution.

How to make NUnit stop executing tests in a Class on a failure

Is there any way to make NUnit abort running any more tests in that class only when it encounters the first error? I'm running integration tests, using the [Order] attribute. These tests can get quite lengthy, and in certain cases there's no need to continue running tests in the class if one of the tests fail. I want NUnit to continue on to other classes, but I want it to abort calling any more classes in that specified class.
Is there any way to do this?
I'm using NUnit 3.2
Thanks!
Buzz
There isn't currently any way to stop execution of tests within a class on first error. There is only the command line option --stoponerror which stops running all tests on the first error.
The Order attribute is new in 3.2. Unlike other frameworks, it was only intended to order your tests, not setup dependencies for your tests. There is an open enhancement on GitHub for a Test Dependency Attribute, but it hasn't been worked on because people cannot come to a consensus on the design. I think a good first step would be a variation of the Order attribute with dependencies, but some people want a full dependency graph. I would recommend that you head over to GitHub and comment on the issue with your requirements.

Coderush Unit Test Runner and Assert.Inconclusive

Can the coderush unit test runner recognise an NUnit Inconclusive assertion as something other than a failure. Perhaps something more like ignored rather than failed?
I am comparing this to resharpers treatment of inconclusive assertions. Is so do I need to configure this and how?
I apologize, but CodeRush can't do that at the moment. If you post a suggestion via the DevExpress Support Center, they will consider implementing it in the future.