Open rebekevsha opened 2 years ago
@rebekevsha, I don't understand what you're trying to accomplish. Can you elaborate?
@kalebpederson Sorry, my english no so fine, but i try))
I need next:
before run ALL tests in namespace i need register my KafkaConsumer as RegisterSingleton(this i can do with your library, thank you)
after that, ONCE before run ALL tests i need run long live task (_kafkaConsumer.StartConsume()) , for consume messages in all testrun lifecikle
For this case, NUnit have SetUpFixture attribute for class, and it say that it Once before all tests run method with [OneTimeSetUp] attribute and Once after all tests run method with [OneTimeTearDown] attribute. And I want use Your DI liberary to resolve my _kafkaConsumer in this class. Because when set [OneTimeSetUp] and [OneTimeTearDown] methods in my class with tests or in parent class, they called as many times as I have classes with tests.
Somethink like thiss:
So, i think i need some custome attribute like [SetUpFixture] with all [SetUpFixture] functionality and additionally an injecting opportunity.
Can u help? Thanks!!!
Maybe you give me some clue where from to start to implement. Maybe some technical nuance. Thanks!!!
Maybe you give me some clue where from to start to implement. Maybe some technical nuance. Thanks!!!
You're pretty close. The [SetUpFixture] attribute needs to change to the [DependencyInjectingTestFixture] and then the constructor needs to become public:
[DependencyInjectingTestFixture]
public class KafkaTests
{
private readonly KafkaConsumer<TestType> _kafkaConsumer;
public KafkaTests(KafkaConsumer<TestType> kafkaConsumer)
{
_kafkaConsumer = kafkaConsumer;
}
[OneTimeSetUp]
public void OneTimeSetUp()
{
Task.Factory.StartNew(() => _kafkaConsumer.StartConsume(), ...);
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
_kafkaConsumer.DisposeAsync().GetAwaiter().GetResult();
}
[Test]
public void Test1()
{
// do something with _kafkaConsumer
}
[Test]
public void Test2()
{
// do something with _kafkaConsumer
}
}
@rebekevsha, my apologies. I didn't read what you posted carefully enough. I'll need to test that to confirm.
@rebekevsha, I have confirmed that this can be implemented within NUnit.DependencyInjection and will plan on working on it as soon as opportunity allows.
@kalebpederson There was no time to answer, since I'm from Ukraine and I think you know what's going on here. So I was a little busy.
Great!!!!! I'll wait!! Because this feature will help me make my tests more compact, flexible and faster.
Thank you!!!
I need to use injection in my SetUpClass with [SetUpFixture] attribute to run SomeMethod with [OneTimeSetUp] attribute where i want use injection. Maby u can help.