Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is there a way to run nunit Test class 50 times in a loop ?

Is there a way to run nunit Test class 50 times in a loop ?

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subin Mavunkal
    wrote on last edited by
    #1

    Is there a way to run nunit Test class 50 times in a loop ? For example I have a class like [TestFixture] public class DemoFailureTeste Can I run it 50 times successively ?

    P B J 3 Replies Last reply
    0
    • S Subin Mavunkal

      Is there a way to run nunit Test class 50 times in a loop ? For example I have a class like [TestFixture] public class DemoFailureTeste Can I run it 50 times successively ?

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Of course you can. Just move the code that you want testing into a for loop. I would probably move it into a method on its own and just call that from the loop if I were you.

      Forgive your enemies - it messes with their heads

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      S 1 Reply Last reply
      0
      • P Pete OHanlon

        Of course you can. Just move the code that you want testing into a for loop. I would probably move it into a method on its own and just call that from the loop if I were you.

        Forgive your enemies - it messes with their heads

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        S Offline
        S Offline
        Subin Mavunkal
        wrote on last edited by
        #3

        But it will recall the methods only , right ? I need to reload the class itself :( .Any idea ?

        P 1 Reply Last reply
        0
        • S Subin Mavunkal

          But it will recall the methods only , right ? I need to reload the class itself :( .Any idea ?

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          What are you trying to achieve? There is no inbuilt way to run the tests n times, so you'd end up having to code for this yourself.

          Forgive your enemies - it messes with their heads

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          S 1 Reply Last reply
          0
          • P Pete OHanlon

            What are you trying to achieve? There is no inbuilt way to run the tests n times, so you'd end up having to code for this yourself.

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            S Offline
            S Offline
            Subin Mavunkal
            wrote on last edited by
            #5

            Yeah , I was looking for some inbuilt attributes.There are no such attributes.I am getting an intermediate failure.So need to figure it out.

            P 1 Reply Last reply
            0
            • S Subin Mavunkal

              Yeah , I was looking for some inbuilt attributes.There are no such attributes.I am getting an intermediate failure.So need to figure it out.

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              You could always write a quick test harness console application, load the class in and look for methods that have this attribute associated with them. It's fairly trivial to execute them once you have this info.

              Forgive your enemies - it messes with their heads

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              1 Reply Last reply
              0
              • S Subin Mavunkal

                Is there a way to run nunit Test class 50 times in a loop ? For example I have a class like [TestFixture] public class DemoFailureTeste Can I run it 50 times successively ?

                B Offline
                B Offline
                buchstaben
                wrote on last edited by
                #7

                You could try Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute. I use it to run my test with different testdata:

                [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
                "|DataDirectory|\\MyDataSource.xml",
                "Row",
                DataAccessMethod.Sequential)]

                P 1 Reply Last reply
                0
                • B buchstaben

                  You could try Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute. I use it to run my test with different testdata:

                  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
                  "|DataDirectory|\\MyDataSource.xml",
                  "Row",
                  DataAccessMethod.Sequential)]

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  buchstaben wrote:

                  You could try Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute.
                   
                  I use it to run my test with different testdata:

                  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
                  "|DataDirectory|\\MyDataSource.xml",
                  "Row",
                  DataAccessMethod.Sequential)]

                  I really can't see how this helps the OP. The question specifically asks about NUnit, and he hasn't asked how to associate a datasource with his test; the question asks how to run the same test class multiple times.

                  Forgive your enemies - it messes with their heads

                  "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                  My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                  B 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    buchstaben wrote:

                    You could try Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute.
                     
                    I use it to run my test with different testdata:

                    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",
                    "|DataDirectory|\\MyDataSource.xml",
                    "Row",
                    DataAccessMethod.Sequential)]

                    I really can't see how this helps the OP. The question specifically asks about NUnit, and he hasn't asked how to associate a datasource with his test; the question asks how to run the same test class multiple times.

                    Forgive your enemies - it messes with their heads

                    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                    My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                    B Offline
                    B Offline
                    buchstaben
                    wrote on last edited by
                    #9

                    you're right. haven't seen the n in "nunit".. nevertheless using (nearly empty) datasource is a way to achieve multiple testruns -> should work with nunit as well.

                    1 Reply Last reply
                    0
                    • S Subin Mavunkal

                      Is there a way to run nunit Test class 50 times in a loop ? For example I have a class like [TestFixture] public class DemoFailureTeste Can I run it 50 times successively ?

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #10

                      Bad idea. The point of unit test is to verify that the code works. That isn't your goal here. So what you need to is the following. 1. Create some code that demonstrates the failure. NOT a unit test itself but it certainly as a method that is suitable for use in a unit test. 2. Create a unit test that calls the code of 1. 3. Figure out the bug by running 2. 4. Re-write 1/2 as necessary to insure that the unit test run will verify, now and in the future, that your code works and continues to work. By the way intermittent failures are often due to threads. So if you don't have any unit tests that test threading you need to add those.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups