TestCase and SetUp attributes for test class

1,135 views
Skip to first unread message

Євген Чорнобривець

unread,
Feb 24, 2011, 11:44:51 AM2/24/11
to NUnit-Discuss
Good day.

Suppose i have one method with [Test] parameter which will be the test
method. I want him to use TestCases, suppose with TestCase
attribute(maybe later with TestCaseSource). Like i understand, method
with SetUp attribute is running before every TestCase. So, can i
somehow pass parameters of test case to SetUp Method.

Thank for any help.

Charlie Poole

unread,
Feb 24, 2011, 12:17:56 PM2/24/11
to nunit-...@googlegroups.com
Hi Evgeny,

No, there is no facility to pass information to the SetUp method indicating what
arguments will be used when the test method is called.

We could consider having parameters passed to the SetUp method itself or
allowing it to access the arguments to the Test method in a future release,
but we would need to have a strong use case for doing it.

Charlie

2011/2/24 Євген Чорнобривець <cherno...@gmail.com>:

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

Євген Чорнобривець

unread,
Feb 25, 2011, 9:07:30 AM2/25/11
to NUnit-Discuss
Good day Charlie.

Thank you for your answer.
In this case, i dont really understand the purpose of SetUp method.
For me its clearly, that this method should put object, which will be
tested in correct state. This means that he should know the test case
conditions. I understand, that all test case options can be puted to
object directly in test method, but in this case there is no point in
SetUp method. Its only my opinion, ofcourse.

Best Regards,
Yevgeniy Chernobrivets

On 24 Лют, 19:17, Charlie Poole <nunit...@gmail.com> wrote:
> Hi Evgeny,
>
> No, there is no facility to pass information to the SetUp method indicating what
> arguments will be used when the test method is called.
>
> We could consider having parameters passed to the SetUp method itself or
> allowing it to access the arguments to the Test method in a future release,
> but we would need to have a strong use case for doing it.
>
> Charlie
>
> 2011/2/24 Євген Чорнобривець <chernobriv...@gmail.com>:
>
>
>
> > Good day.
>
> > Suppose i have one method with [Test] parameter which will be the test
> > method. I want him to use TestCases, suppose with TestCase
> > attribute(maybe later with TestCaseSource). Like i understand, method
> > with SetUp attribute is running before every TestCase. So, can i
> > somehow pass parameters of test case to SetUp Method.
>
> > Thank for any help.
>
> > --
> > 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 athttp://groups.google.com/group/nunit-discuss?hl=en.- Сховати цитований текст -
>
> - Показати цитований текст -

Charlie Poole

unread,
Feb 25, 2011, 2:52:03 PM2/25/11
to nunit-...@googlegroups.com
Hi Yevgeniy,

The original purpose of SetUp and TearDown was to create the common
state needed for all the tests in a class. This common state - generally
called a "fixture" - is the original of the terminology we use for a class
that contains tests: TestFixture.

Things have changed a bit since xUnit frameworks were first created
and other principles of organization have come forward. Nevertheless,
most people believe that a test class where many methods do not
make use of all the objects in the fixture should be split.

As an example, imagine I am testing the presenter class of an
MVP triad. In the SetUp, I will create a model object, a view
and the presenter itself. I will perform any common setup needed
for all the tests in this class. Then, in each test method, I will
perform any additional actions needed for that particular test.

Does that make the intention clearer?

Charlie

2011/2/25 Євген Чорнобривець <cherno...@gmail.com>:

Charlie Poole

unread,
Sep 7, 2012, 9:33:27 AM9/7/12
to nunit-...@googlegroups.com
Hi,

This seems like something that would vary at the fixture level, not
the test case.

By mixing tests that do different things (test different databases) in the same
fixture, you are creating the need to run a different setup for each test. This
defeats the purpose of using the same setup for each test in a fixture.

On the other hand, you probably want to do _almost_ the same thing for
each test... that is, you want to run the same tests against a
different database.

In the past, this was done by using inheritance. In current versions of NUnit,
you can use a parameterized test fixture, passing the connection string or
other information about the database as an argument.

If the structure of your tests allow you to do the initialization
once, then you
can do it in the TestFixtureSetUp method. Otherwise, continue to use the
SetUp method. Use the information passed in the constructor to set up
the particular database for use.

Charlie

On Thu, Sep 6, 2012 at 10:55 PM, lisamariet <lisam...@gmail.com> wrote:
> Hi,
>
> Have a case now that I would benefit from having this functionality. Writing
> NHibernate integration tests. Have tests that I would like to run agains 3
> databases, Same test, but databasestring is different.
> If Setup could read parameters supplied in TestCase I could pass in an Enum
> specifying which database and still handle Session stuff in Setup in stead
> of having to handle it in every test method.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nunit-discuss/-/3S-5Qs54LX4J.
Reply all
Reply to author
Forward
0 new messages