Search Unity

Unit testing Entities.ForEach

Discussion in 'Data Oriented Technology Stack' started by Liquid_Nalee, Sep 3, 2021.

  1. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    I'm trying to figure out good CI/CD practices in DOTS especialy with Entities.ForEach.
    The code beeing stateless should make unit testing very potent and one very simple approach would be to keep all logic in Job structs and then test the state of variables after Execute()

    Using Job structs over Entities.ForEach though makes for more wordier code and one would rather go with the latter but then how does one best unittest the code inside the lambda (since we can't use static functions in there with Burst last I heard)

    My instinct scream "inject dependencies" and thus make an object u pass to the service that implements required methods that you may test outside of the service... but that's literaly what a job is already.

    Any ideas ?
     
    apkdev likes this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    2,519
    Do you mean that you can't put lambdas inside of static functions or that you can't put static function calls inside lambdas? The former is true. The latter is not.

    If calling Update() on a system isn't granular enough, what you can do instead is put your lambdas inside member functions and call those from your tests.
     
    Liquid_Nalee likes this.
  3. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    I meant the latter, I was convinced there was a whole thread about how we cant call outside static functions from inside a Job.WithCode. My bad then, forget what I said. Thanks ^^
     
  4. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    Turns out there is more annoying stuff like how you cant mock structs but burst doesnt support boxing structs with interfaces. I'm not sure yet if it's just a warning and when compilation runs and the underlying type is really a struct then it won't cause any problems or if it's going to break and then i'm not sure how I go from there to make my tests
     
  5. Liquid_Nalee

    Liquid_Nalee

    Joined:
    Mar 15, 2021
    Posts:
    19
    It does work, just annoying to get warnings but I can live with that
     
unityunity