I need to pass test data on class level but Theory
and InlineData
attributes can only be used on methods.
public class ContainerTests : TestFixture
{
private IContainer _container;
public ContainerTests(string containerName)
{
_container = CreateContainer(containerName);
}
[Fact]
public void ResolveJobFactory()
{
IJobFactory jobFactory = _container.Resolve<IJobFactory>();
}
private IContainer CreateContainer(string containerName)
{
if (containerName == "CastleWindsor")
{
return new WindsorContainerAdapter();
}
//other adapters
throw new NotImplementedException();
}
}
Is there a way to achieve something similar in xUnit.net?
Java does not support "multiple inheritance" (a class can only inherit from one superclass). However, it can be achieved with interfaces, because the class can implement multiple interfaces. Note: To implement multiple interfaces, separate them with a comma (see example below).
A test can exercise methods from three objects and still be a unit test. Some may claim that's integration but three lines of code are just as "integrated" so that's not really a thing. Method and object boundaries don't present any significant barrier to testing.
Unit testing is a software development process in which the smallest testable parts of an application, called units, are individually and independently scrutinized for proper operation. This testing methodology is done during the development process by the software developers and sometimes QA staff.
Testing multiple implementations of an interface in a single test class
Don't! Have a test class per implementation.
Edit: As per comments, I recommend having a base TestClass with all of the common tests, and then a Test Class per implementation which inherits from this base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With