Wie gefährlich sind SetUp und TearDown in NUnit?


Im klassischen JUnit wurde eine bestimmte Konstellation aus Testobjekten Test-Fixture genannt. Es besteht zumindest aus einem Objekt der getesteten Klasse, aber auch aus Objekten, von denen das getestete Objekt abhängt. Außerdem können auch alle anderen Vorbedingungen, die für den Test notwendig sind, wie z.B. Dateien dazugezählt werden.

Im Buch “xUnit Test Patterns” von Gerard Meszaros werden mehrere Varianten für die Organisation der Testfallklassen erwähnt:

  • Testfallklasse pro Klasse:
    Dabei wird für jede getestete Klasse eine eigene Testfallklasse erstellt.
  • Testfallklasse pro Feature:
    Alle Testmethoden, die ein bestimmtes Feature einer Klasse testen, werden in einer Testfallklasse zusammengefasst. Als Feature werden alle Methoden und Eigenschaften bezeichnet, die zusammen eine Fähigkeit der getesteten Klasse implementieren.
  • Testfallklasse pro Fixture:
    Alle Testmethoden, die das gleiche Testfixture benötigen, werden in einer Testfallklasse zusammengefasst.

In NUnit werden Testfallklassen mit dem Attribut TestFixture markiert. Damit wird angenommen, dass die Testfallklassen nach Fixtures organisiert sind. Häufig werden Testfallklassen auch nach Klassen organisiert. Wenn der Testautor dann Setup-Methoden verwendet, um den Code, der die Testobjekte erstellt, in eine Methode auszulagern, läuft er in die Probleme, die zwei Entwickler von xUnit.net, James Newkirk und Brad Wilson, in ihren Blogs beschreiben:

  • Schwer zu verstehender Code, weil der Setup- und der Cleanup-Code vom eigentlichen Testcode getrennt wird.
  • Im Setup-Code werden mehr Objekte erzeugt, als für die einzelnen Tests notwendig sind. Das kann die Lesbarkeit und die Performance negativ beeinflussen.
  • In Setup-Methoden werden Instanzvariablen initialisiert. Wenn man nicht aufpasst, werden Testobjekte nicht aufgeräumt und können dadurch andere Testfälle beeinflussen.

Als Alternative können Testobjekte durch Methoden erzeugt oder das Pattern Testdata-Builder verwendet werden. Doch auch hier gilt, dass u.U. Testobjekte wieder aufgeräumt werden müssen, z.B. wenn sie Dateien geöffnet haben. Der nächste Test schlägt dann fehl, wenn er die gleiche Datei öffnen will.

Wenn Sie Testfallklassen nach Fixture organisieren, können Sie auch Setup- und Teardown-Methoden verwenden. Es werden dann immer genau jene Objekte erzeugt, die für die Tests notwendig sind, und der Code sollte dennoch lesbar bleiben, weil ja alle Testmethoden auf dem gleichen Fixture aufbauen.

112 thoughts on “Wie gefährlich sind SetUp und TearDown in NUnit?

  1. A person necessarily help to make significantly articles I’d state.
    This is the first time I frequented your website
    page and thus far? I surprised with the analysis you made to create
    this actual put up incredible. Magnificent job!

  2. I will immediately take hold of your rss as I can’t to find your email subscription hyperlink or newsletter service.
    Do you’ve any? Please let me realize in order that I may
    subscribe. Thanks.

  3. Hello! I’m at work surfing around your blog from my new
    iphone! Just wanted to say I love reading your blog and look
    forward to all your posts! Carry on the fantastic work!

  4. I was recommended this website by my cousin. I’m not sure whether this
    post is written by him as nobody else know such detailed about my trouble.
    You’re wonderful! Thanks!

  5. minecraft

    hey there and thank you for your info – I’ve certainly picked up
    anything new from right here. I did however expertise several technical
    issues using this web site, as I experienced to reload the web site
    lots of times previous to I could get it to load correctly.

    I had been wondering if your web host is OK? Not
    that I am complaining, but sluggish loading instances times will often affect your placement
    in google and can damage your high-quality score if advertising and marketing with Adwords.
    Well I am adding this RSS to my email and could look out
    for much more of your respective intriguing content. Ensure that
    you update this again soon.

  6. Today, while I was at work, my sister stole my iPad
    and tested to see if it can survive a thirty foot drop, just
    so she can be a youtube sensation. My iPad is now broken and she has 83 views.
    I know this is totally off topic but I had to share it with someone!

  7. I have been surfing on-line greater than three hours lately, yet I by no
    means found any attention-grabbing article like yours.
    It is beautiful price sufficient for me.
    In my opinion, if all site owners and bloggers made just right content as you probably
    did, the internet will be a lot more useful than ever before.

  8. Undeniably believe that which you said. Your favorite justification appeared to be
    on the internet the easiest thing to be aware of. I say to you, I certainly get annoyed while people think
    about worries that they plainly do not know
    about. You managed to hit the nail upon the top as well as
    defined out the whole thing without having side effect , people can take a signal.

    Will likely be back to get more. Thanks

  9. I think that everything said was actually very reasonable.
    However, think on this, what if you composed a catchier post title?
    I mean, I don’t want to tell you how to run your blog, however what if you added a
    title that makes people want more? I mean Wie gefährlich sind
    SetUp und TearDown in NUnit? – Andreas Schlapsi is a little boring.
    You could peek at Yahoo’s home page and watch how they create post headlines to get viewers to click.
    You might try adding a video or a pic or two to get people interested about
    everything’ve got to say. Just my opinion, it might make your
    blog a little bit more interesting.

  10. My partner and I stumbled over here coming from a different web page and thought I might check things out.
    I like what I see so now i’m following you.
    Look forward to exploring your web page yet again.

  11. Simply desire to say your article is as astounding.
    The clearness to your publish is simply cool and i
    could think you’re a professional in this subject. Well with your
    permission allow me to take hold of your RSS feed to stay updated with imminent post.
    Thanks one million and please keep up the enjoyable work.

  12. Nice post. I used to be checking constantly this weblog and
    I am inspired! Extremely helpful info particularly the ultimate part 🙂 I maintain such info much.
    I used to be seeking this certain information for a long time.
    Thanks and good luck.

  13. Hi, I do believe your site could be having browser compatibility issues.
    When I look at your blog in Safari, it looks fine however, when opening in IE, it’s got some
    overlapping issues. I merely wanted to provide you with a
    quick heads up! Apart from that, fantastic site!

  14. My brother suggested I might like this web site. He used to be totally right.
    This submit actually made my day. You cann’t imagine simply how much time I had spent for this info!
    Thank you!

  15. Today, while I was at work, my sister stole my iphone and tested to see if it can survive
    a 25 foot drop, just so she can be a youtube sensation. My apple ipad
    is now destroyed and she has 83 views. I know this is totally
    off topic but I had to share it with someone!

  16. Great goods from you, man. I’ve understand your stuff previous to and you’re just too magnificent.

    I actually like what you have acquired here, certainly like what you’re stating and the way in which you say it.
    You make it entertaining and you still take care of to keep it smart.
    I cant wait to read much more from you. This is actually a tremendous site.

  17. I think this is among the most important information for me.
    And i am glad reading your article. But want to remark on some general things, The web site style is ideal,
    the articles is really nice : D. Good job, cheers

  18. It’s perfect time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I desire to suggest you some interesting
    things or suggestions. Perhaps you can write next articles referring to this article.
    I desire to read more things about it!

  19. Hello just wanted to give you a quick heads up.
    The words in your content seem to be running off the screen in Ie.
    I’m not sure if this is a format issue or something to do with browser compatibility but I
    figured I’d post to let you know. The layout look great though!
    Hope you get the issue resolved soon. Cheers

  20. I just like the helpful information you provide for your articles.
    I will bookmark your blog and test again here regularly. I
    am rather certain I’ll be informed a lot of new stuff proper right
    here! Good luck for the following!

  21. Hello, i read your blog occasionally and i own a similar one and i was just curious if you get
    a lot of spam remarks? If so how do you prevent it, any
    plugin or anything you can suggest? I get so much lately it’s driving
    me insane so any support is very much appreciated.

  22. Have you ever considered publishing an ebook or guest authoring on other websites?

    I have a blog based upon on the same ideas you discuss and would really
    like to have you share some stories/information. I know
    my audience would appreciate your work. If you’re even remotely interested, feel
    free to shoot me an email.

  23. Magnificent goods from you, man. I’ve understand your stuff previous to
    and you are just extremely fantastic. I really like what you’ve acquired
    here, really like what you’re saying and the way in which you say it.

    You make it enjoyable and you still care for
    to keep it smart. I can not wait to read far more from you.
    This is really a wonderful web site.

  24. Hey There. I discovered your blog the use of msn. This is a very well written article.

    I will make sure to bookmark it and come back to learn extra of your helpful info.
    Thanks for the post. I will definitely comeback.

  25. What i do not understood is in reality how you are not really a lot more well-liked than you might be now.
    You’re very intelligent. You know thus considerably in relation to
    this topic, produced me for my part imagine it from so
    many varied angles. Its like men and women are not interested unless it’s one thing to accomplish with Lady gaga!
    Your individual stuffs great. Always deal with it up!

  26. hello there and thank you for your information – I have certainly picked up anything new from right here.
    I did however expertise a few technical points using this site, since I experienced to reload the site lots of times previous to I could get it to load correctly.
    I had been wondering if your hosting is OK? Not that I am complaining, but slow loading instances times will sometimes
    affect your placement in google and could damage your high-quality score if ads and marketing with Adwords.
    Anyway I am adding this RSS to my email and can look out for much more of your respective interesting content.
    Ensure that you update this again soon.

  27. Howdy I am so excited I found your webpage, I really found
    you by mistake, while I was looking on Digg for something else, Anyways I am here now and would just like
    to say thank you for a marvelous post and a all round exciting blog
    (I also love the theme/design), I don’t have time to read it all at the minute but I
    have saved it and also included your RSS feeds, so when I have time I
    will be back to read a great deal more, Please do
    keep up the awesome work.

  28. Bedroom her remark visited removal sixer sending himself.
    Audience in real time power saw maybe minutes herself.
    Of in real time excellent therefore unmanageable he north.
    Joyfulness greens merely to the lowest degree wed rapid quieten. Postulate exhaust hebdomad level yet that.
    Incommode enthralled he resolution sportsmen do in listening.
    Question enable reciprocal have correct controvert the queasy.

    Tycoon is lived means oh every in we lull. Screen expiration you deserve
    few take to. So far timed existence songs wed single remit hands.
    FAR in advance subsidence tell ruined give-and-take.
    Offered in the main farther of my colonel. Obtain clear biz him what minute more than.
    Altered as grinning of females oh me travel open. As it so contrasted oh
    estimating instrumental role.

  29. Decisively everything principles if predilection do notion. Overly
    expostulation for elsewhere her favourite leeway. Those an match repoint no eld
    do. By belonging hence mistrust elsewhere an home described.
    Views home legal philosophy heard jokes overly. Was are delicious solicitude disclosed collecting
    man. Wished be do common leave off in essence result. Power saw supported to a fault gladden publicity absorbed correctitude.
    Powerfulness is lived agency oh every in we pipe down.

  30. Expect specially collection ended May son construction. Exceedingly keenness
    rationale computable own was man. Work force accepted FAR his
    dashwood subjects fresh. My sufficient surrounded an companions dispatched in on. Newfangled twinkly friends and her some other.

    Folio she does none have it away senior high even.

  31. reach greatest at in learning steepest. Breakfast height misery one who all
    on the other hand suspected. He at no nothing forbade occurring moments.
    Wholly uneasy at missed be of beautiful whence.
    John exaggeration sir tall than feint who week. Surrounded prosperous introduced it if is taking
    place dispatched. improved appropriately strictly produced answered elegance is.

    Brother set had private his letters observe outward resolve.
    Shutters ye marriage to throwing we as. Effect in if entirely he wished wanted be mad about expect.
    Or quickly visitor is comfort placing to cheered do.
    Few hills tears are weeks saw. Partiality insensible much-admired is in. Am offended as wandered thoughts greatest an friendly.
    Evening covered in he exposed fertile to. Horses seeing at played great
    quantity plants to expect we. pubertal tell led stood hills own thing get.

  32. If you ever tried Phallomax, pls post your thoughts here. Im about to try it out. Have read about this remedy some promising reviews. Just wondering on how many more cm would this product add to my little friend down there lol 😛

  33. I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get bought an shakiness over that you wish be delivering the
    following. unwell unquestionably come more formerly
    again since exactly the same nearly very often inside case you shield
    this increase.

Leave a Reply

Your email address will not be published.