parameterized testing in nunit-console

593 views
Skip to first unread message

deedee

unread,
Nov 9, 2011, 5:39:24 PM11/9/11
to NUnit-Discuss
Hi,
I know that I can run parameterized tests from the console using the
following command:

nunit-console-x86.exe my_test.dll /
run=MyUnitTest.TestClass1.TestMethod1(\"MyString\")

but that requires that I mention the "MyString" as a TestCaseAttribute
on the test. Is there a way to pass any string as a parameter to the
test (without having it mentioned as [TestCase("some-string")] in the
test?
Can a TestCase be created programmatically?

Thanks,
Message has been deleted

deedee

unread,
Nov 10, 2011, 10:32:25 AM11/10/11
to NUnit-Discuss
Also, the string that is to be passed is entered by a user input, and
not a
set of strings stored in a file somewhere. I guess there is a
possibility
that I store the user input somewhere, and use that file content as a
TestCaseSourceAttribute value. I just don't think it's the most
elegant way of
doing it..especially if there's just one string to be passed at a
time.

Charlie Poole

unread,
Nov 10, 2011, 10:48:22 AM11/10/11
to nunit-...@googlegroups.com
Hi,

Answering all at once...

1) There is no current way to pass a parameter for a test at the command
line. It has been requested and will be in a future release.

2) I think it's a rather good idea you suggest: pass in a string as a
parameter at the command line and have NUnit create the test on the
fly. Unfortunately, that's not possible either. The tests must be created
by having the argument appear somewhere in the code.

3) The inelegant solution of storing the input in a file is really the only
way to do it right now.

Charlie

> --
> 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.
>
>

deedee

unread,
Nov 10, 2011, 11:26:52 AM11/10/11
to NUnit-Discuss
Thanks for your reply, Charlie.
For some reason the idea of the TestCaseSourceAttribute works when I
am running the test in Visual studio. However, if I run the same
command in the console, it selects the right test, however doesn't run
any test. Any ideas what could be wrong?

>nunit-console-x86.exe my_test.dll /run=MyUnitTest.TestClass1.TestMethod1(\"MyString\")

ProcessModel: Default DomainUsage: Single
Execution Runtime: Default
Selected test(s): MyUnitTest.TestClass1.TestMethod1("MyString")
Tests run: 0, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0070007
seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

where "MyString" is a string stored in a file, that is being read by
the Property used as the TestCaseSource

Thanks,

On Nov 10, 8:48 am, Charlie Poole <nunit...@gmail.com> wrote:
> Hi,
>
> Answering all at once...
>
> 1) There is no current way to pass a parameter for a test at the command
> line. It has been requested and will be in a future release.
>
> 2) I think it's a rather good idea you suggest: pass in a string as a
> parameter at the command line and have NUnit create the test on the
> fly. Unfortunately, that's not possible either. The tests must be created
> by having the argument appear somewhere in the code.
>
> 3) The inelegant solution of storing the input in a file is really the only
> way to do it right now.
>
> Charlie
>

Charlie Poole

unread,
Nov 10, 2011, 12:02:27 PM11/10/11
to nunit-...@googlegroups.com
My guess is that your property has not been initialized at the point
where NUnit loads the tests. How are you initializing it?

Charlie

deedee

unread,
Nov 10, 2011, 12:39:46 PM11/10/11
to NUnit-Discuss
That is so right! The property wasn't an auto property, so I I wasn't
initializing them specifically in one place. Now it works fine. I was
thinking of putting it in the static constructor of my test class, do
you it will be Ok to have it there?

On Nov 10, 10:02 am, Charlie Poole <nunit...@gmail.com> wrote:
> My guess is that your property has not been initialized at the point
> where NUnit loads the tests. How are you initializing it?
>
> Charlie
>

Charlie Poole

unread,
Nov 10, 2011, 12:51:11 PM11/10/11
to nunit-...@googlegroups.com
That should work.

Charlie

Reply all
Reply to author
Forward
0 new messages