1

I need to be able to pass a reference object to a test class constructor and use that inside test initialize methods to use them within test methods. I also need to be able to configure test runner and run from some point of invocation like a console application or from button click in a form application. How to achieve this in NUnit framework? In short I need to pass a variable to test class and use it instead of declaring it inside and I should be able to run test runner from my own application.

Hewitt V S
  • 11
  • 3
  • There are two different questions here, which are completely unrelated, which the StackOverflow Gods tend not to like. You can use TestCaseSource attribute to supply test scenarios dynamically from a static method that you write yourself (including creating reference objects, but giving them to tests rather than the constructor). NUnit can be run via its console. Both can be found documented on the NUnit website. – Richardissimo Apr 03 '18 at 15:40
  • @Richardissimo My need differs from a typical unit test scenario.I am not trying to do unit testing. I will launch an application. I will expose all the reference objects in a hugh container object(that's where I needed constructor variables). I will make method calls on real objects and assertions on real data. No mocking, faking what so ever. That's my need. To run the test,I found NUnit test engine is good than console in my case. Only problem I have is test engine running the test, which has real object method calls resulting in UI update causes cross thread access exception.Can you help? – Hewitt V S Apr 04 '18 at 16:28
  • No problem, you're just doing integration testing with NUnit. I still don't see a value in having your own application launch the tests, compared to the NUnit UI where you can pick and choose which tests to run; but you can do that if you like. You can use things like OneTimeSetup to prepare things that need to be in place before your tests in a TestFixture start. And if you need an overarching framework to be available for multiple TestFixtures, you could code that yourself. The issue of interaction with UI layer can be solved by separation of concerns below the UI layer, or... – Richardissimo Apr 04 '18 at 21:13
  • ...using a UI automation testing tool, which isn't what NUnit is designed for. For myself, unit testing and mocking give me all that I need, and I'm a professional. I use integration tests for my data layer, but mocking above that. If you'd like to understand why I prefer that over integration tests for everything, take a look at Update 2 to [this answer](https://stackoverflow.com/questions/49332471/mock-verify-invocation/49332840#49332840). I hope this helped. Good luck. – Richardissimo Apr 04 '18 at 21:16
  • @Richardissimo It's just an experiment. The data structure is so complex, we need it in original form. That's why we are avoiding mocking and stuff. Everything has to happen the way it's designed to be. Still, each of the use cases looks like joining many unit tests altogether. That's why Nunit can fit in. We could have used UI testing tool. It will take time to detect the control and invoke it. Comparing that to method calls, the time taken will be far less. – Hewitt V S Apr 06 '18 at 01:41

0 Answers0