On Thu, Apr 21, 2011 at 2:03 AM, Mahesh Narayan <naraya...@gmail.com> wrote:
> Hi,
> I am a test automation lead in my organization We have developed a
> custom automation framework to do testing of our products. The product
> and automation framework are both in C#.
>
> Currently, we have coded all our test cases as C# classes that get
> invoked through NUnit. The classes have the [TestFixture] attribute
> and also the Execute() function that NUnit recognizes and invokes.
I don't understand. NUnit does not recognize or invoke any function
called "Execute" on the user fixture class. It calls methods marked
with particular attributes.
> We will be moving to a new test runner different than NUnit shortly.
> We want to minimize our code changes. Hence, I would like to see
> whether I can still launch NUnit programmatically behind the scene
> when my new test runner executes.
When you say "launch NUnit" what parts of NUnit are you wanting
to launch? I guess you don't want to run nunit.exe or nunit-console.exe,
but there are various levels at which you could consider using NUnit,
since it is essentially a layered application.
Perhaps you could describe what your own runner will do and what you
would like NUnit to do.
> Once NUnit is launched (with appropriate command line arguments), my
> existing classes would still work because they are NUnit compatible.
OK... now I see "command-line arguments" so I'll contradict myself.
Apparently you want to run either nunit-console.exe or nunit.exe
programmatically. But I won't change the prior statements because
it would still help if you explained a bit more
> Please let me know how I can do this. It is urgent. Does Nunit have a
> list of APIs that I could invoke?
OK... more confusion. If you are simply launching the executable, no
API is needed - or possible. If you want to make use of some NUnit
internals by using (for example) nunit.core.dll, then the need for an
API makes sense. However, these two approaches would appear to
be mutually exclusive. Can you explain further?
One small comment. NUnit currently has no formally supported API
for external use, so whatever you do is adhoc and could be changed
in a future release. Obviously, some things are less likely to change
than others and I can help advise you on that. One of the main
goals of NUnit 3.0 is to provide a public API for using NUnit.
Sorry for my confusion. I think it's because you have a certain way
of using NUnit in your mind and I am thinking of three or four
different ways you might do it. If you can give more details, we'll
try again!
Charlie
> Thanks and Regards,
> Mahesh.
>
>
> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>
Your example makes it clearer to me.
Here are some options you might consider, from highest level to lower level:
1. Just launch a process running nunit-console.exe, passing in command line
arguments that tell it what assembly to load and what tests to
run. For example:
nunit-console.exe mytests.dll -run="testfixture1,testfixture2,testfixture3"
I suggest experimenting with doing this manually first before trying it
programmatically.
You can also use nunit.exe this way, but with no ability to select
tests to run.
2. Use nunit-console-runner.dll and execute Runner.Main, passing in an array of
arguments. This is the same as running nunit-console.exe except you don't
have to launch a separate process.
NOTE: Both of the above will produce the normal nunit-console text output. If
you want control of the output yourself, you most go to a lower level.
3. Use nunit-gui-runner.dll to load the assembly tests in the gui. Execute
AppEntry.Main, passing in the path to your assembly and any other args.
In order to select tests, use Services.TestLoader to get a reference to the
TestLoader and call methods on it to run the tests. You will need
to construct
and pass in a filter in order to select specific tests. See the
source code for
more details.
4. Rather than using the Gui, use TestLoader directly yourself. You will have to
perform some initialization of the services first - see how the
console runner
does it in ConsoleUi.cs as a start.
5. Select some lower level runner and use it directly. For example,
use TestDomain
to run in-process in a separate AppDomain. If you later wanted to
run the tests
in a separate process, then you would have to change your code to use a
ProcessRunner, rather than just changing an option in the TestPackage as
is done when you use TestLoader.
All runners implement the TestRunner interface, which is fairly
straightforward.
Hope this helps you.
Charlie