Search Unity

Resolved Running Only A Subset Of Tests Through Command Line

Discussion in 'Testing & Automation' started by Aceria_, Apr 6, 2019.

  1. Aceria_

    Aceria_

    Joined:
    Oct 20, 2014
    Posts:
    81
    I was wondering if it's possible to run a specific subset of tests when running them through the command line. I'd like to run most of our tests all the time, but some of them aren't that critical and I'd rather have them run overnight instead of slowing down our day-to-day work.

    We run it all through Jenkins on a build server, so I can't just select them manually in the test runner in the editor.
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    The test runner supports a "test filter" option - this is pretty much undocumented (or underdocumented?)
    This allows you to run tests that match a certain name using a filter, so it may not be exactly what u need, but you can rename your tests in such a way that will allow you to run a subset.

    A more useful feature would've been to allow us to specify a category for executing tests via command line. As an old habit, i tag my test fixtures with categories (e.g: integration, slow, fast, etc).

    If i could, i would run a specific category (or a set of categories?) when running from the command line.
    Another option would've been to ignore certain categories (e.g: slow).

    But all of these are not available right now from what i know. the test filter is your best bet right now.
     
    Aceria_ likes this.
  3. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    Hey. The testFilter is indeed available in order to filter test by names. It is however also possible to filter test by categories using the testCategory argument. Both are things that will be documented correctly in the documentation overhaul we are working on.

     
    Xarbrough, Aceria_ and liortal like this.
  4. Aceria_

    Aceria_

    Joined:
    Oct 20, 2014
    Posts:
    81
    The testCategory is exactly what I needed. I think in combination with testFilter that covers all of the use cases I can think of.

    Thanks for the answer liortal & Warnecke!
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    @Warnecke Is there any way to ignore tests or categories?
    For example - we have a lot of tests, but some are really slow. i would like our CI builds to run all tests (except those marked with category 'slow' or something similar).

    On our nightly build we will execute all tests, but for the ones that run many times a day, i would like to avoid running those.
     
  6. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    Currently we do not support exclusive filters, but it should be possible for you to filter out some categories by explicitly specify the categories to include. You can give it "Uncategorized" to pick up tests without categories and then specify the categories to include. I believe that you can provide a regex like "^(?!SlowTest).*" (which would match any category that does not start with SlowTest). Note that it is important to pass both "Uncategorized" and the regex as tests without categories does not go trough the regex, but are just matched against the "Uncategorized" string.
     
  7. Maltesj

    Maltesj

    Joined:
    Feb 7, 2020
    Posts:
    11
    @Warnecke Is there any plans to change this behaviour?
    NUnit has an include/exclude/combination behaviour in their docs, can't you mimic that behaviour with test api?

    https://docs.nunit.org/2.5.1/consoleCommandLine.html
    Beginning with NUnit 2.4.6, you may use a Category Expression with either of these options:

    A|B|C
    Selects tests having any of the categories A, B or C.
    A,B,C
    Selects tests having any of the categories A, B or C.
    A+B+C
    Selects only tests having all three of the categories assigned
    A+B|C
    Selects tests with both A and B OR with category C.
    A+B-C
    Selects tests with both A and B but not C.
    -A
    Selects tests not having category A assigned
    A+(B|C)
    Selects tests having both category A and either of B or C

    It would be an awesome feature imo
     
  8. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    Yes. In the up-comming version 1.1.18 of the test framework package we are adding support for using negation on test filters, categories and assembly names.
     
  9. RGV

    RGV

    Joined:
    Jan 25, 2016
    Posts:
    48
    Bumping this up because we have used category filters for a while, what is essential for CI/CD builds, but we have happened to find a missing feature that we think is so useful and straighforward to implement for test-runner devs: exclude some categories in the project by default.
    Say we have categories "Unit, Integration, Component, e2e, Slow", regardless they are either at PlayMode or EditMode. We want e2e and Slow in some CI/CD pipelines, which is feasible by category filters at command line.
    But we want those two categories not only out of some pipelines but out of any local run of tests. At the momend we are forced to manually set the categories using the dropdown — and that's quite cumbersome.
     
  10. Warnecke

    Warnecke

    Unity Technologies

    Joined:
    Nov 28, 2017
    Posts:
    92
    It sounds to be like you want to mark those slow tests as [Explicit], which will make them only run if the category or another test filter targeting them is given.
     
    Whatever560 and RGV like this.
  11. RGV

    RGV

    Joined:
    Jan 25, 2016
    Posts:
    48
    Totally! I have missed this NUnit feature for years. I really appreciate your help.
     
    Warnecke likes this.