Search Unity

Question Is it possible to run tests and build the player from a single command line call?

Discussion in 'Testing & Automation' started by Xarbrough, Nov 11, 2022.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I'm working on a build script outside of Unity which will call the command line interface of the Editor to build and run tests. Both tasks work fine if I follow the documentation and create two separate calls. This however results in Unity starting, running tests, then closing, re-opening and building the player.

    Is it possible (and sensible) to perform both actions in a single CLI command? It feels like it's wasting time starting the editor twice, when I actually want to run tests and immediately build if all tests pass.

    If the command line interface doesn't support this, would it make sense to implement a C# build script that calls the TestRunnerAPI and then uses the BuildPipeline? Are there any drawbacks speed-wise?
     
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,659
    You could try passing both the build and run-tests options in the same command line but I doubt it would work. Your second idea of a C# build script is more likely to work I think. I don't think there are any major speed considerations; biggest thing to consider is what happens if your project has compile errors.
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Thanks! So I incorrectly thought that it wasn't working in the first place because I also used the "-quit" command line argument. This made the tests not run while the build was correctly being produced. Turns out, the quit options prevents tests from running in any setup, but if I omit it, then tests and build both run. I also found multiple references of build runners like Cake and TeamCity that omit the -quit flag and specifically mention that it doesn't seem to be supported for tests.

    Well anyway, it seems separate steps are the better idea. For example, when running the CLI command, the player isproduced when tests fail, but I would like to not build at all in that case. I also noticed that opening the Unity editor is actually very fast, at least on my machine and with my current setup.
     
    superpig likes this.