NUnit testcase generation: how to create sub-folders (hierarchy)?

381 views
Skip to first unread message

Andrey Simonov

unread,
Nov 10, 2011, 9:26:09 AM11/10/11
to NUnit-Discuss
I am generating NUnit testcases based on the file names.

The directory looks like this:

Customer
CustomerTestCase1.xml
CustomerTestCase2.xml

Account
AccountTestCase1.xml
AccountTestCase2.xml

I am using TestCaseSource:

string[] list = Directory.GetFiles(path, "*",
SearchOption.AllDirectories)

foreach (string file in list)
{
yield return new TestCaseData(file)
}

How do I introduce hierarchy into the generated testcases? I need them
to be organized in groups according to folder structure, so I could
tick "Account" and all the account testcases would be selected.

Charlie Poole

unread,
Nov 10, 2011, 10:43:39 AM11/10/11
to nunit-...@googlegroups.com
Simply put your test cases into separate fixtures and - if necessary - place
the fixtures in separate namespaces.

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

Andrey Simonov

unread,
Nov 10, 2011, 10:46:37 AM11/10/11
to NUnit-Discuss
Hi Charlie,

That would add significant overhead - I'd like to read all the files
in one place.

Is there any way to do this without creating many fixtures?

Or is there a way to generate fixtures automatically?

Andrey

Charlie Poole

unread,
Nov 10, 2011, 10:51:25 AM11/10/11
to nunit-...@googlegroups.com
Hi Andrey,

On Thu, Nov 10, 2011 at 7:46 AM, Andrey Simonov <andr.s...@gmail.com> wrote:
> Hi Charlie,
>
> That would add significant overhead - I'd like to read all the files
> in one place.

Perhaps inheritance could solve that problem for you.

> Is there any way to do this without creating many fixtures?

Well, fixtures are the primary way of organizing tests, so I'm
not sure that's so desirable unless the code you create is
never examined by a person.

> Or is there a way to generate fixtures automatically?

Aren't you already generating one fixture? Perhaps I didn't
really understand what you are doing. Aren't you generating
code for the tests?

Charlie

Andrey Simonov

unread,
Nov 10, 2011, 11:41:55 AM11/10/11
to NUnit-Discuss
Hi Charlie,

Sorry for being not too clear, I am rather new to C# and NUnit.

I have wrote a fixture that generates testcase names from the file
names using TestCaseSource.

I currently do not see how I can automatically generate TestFixtures
as apposed to generating Tests.

By TestFixture I understand the class that has Tests inside it, and
which is shown as a parent folder in NUnit GUI.

My wish is to generate a TestFixture/Test tree that would reflect the
Folder/File file system tree.

On Nov 10, 3:51 pm, Charlie Poole <nunit...@gmail.com> wrote:
> Hi Andrey,
>

Charlie Poole

unread,
Nov 10, 2011, 12:07:30 PM11/10/11
to nunit-...@googlegroups.com
Hi Andrey,

If that structure is dynamic, then there is little you can do. However,
if the structure does not change, then you can simply code multiple
fixtures, with tests that take data from different sources.

So you might have a Customer fixture, pulling test data from some
particular source or sources, and an Account fixture pulling its data
from other sources.

Put the common code for these fixtures into a base class so that
you don't have to repeat the logic. In fact, it should be easy to
refactor directly from what you have to use of a base class and
then to create separate leaf classes for the tests you want to
select separately.

Charlie

Message has been deleted

Andrey Simonov

unread,
Nov 10, 2011, 12:23:56 PM11/10/11
to NUnit-Discuss
Charlie,

Thank you very much, you were very helpful!

Andrey

On Nov 10, 5:07 pm, Charlie Poole <nunit...@gmail.com> wrote:
> Hi Andrey,
>
Reply all
Reply to author
Forward
0 new messages