game-ci / game-ci/unity-test-runner

Feature: Add targetPlatform for tests

Open
#189 2 comments 6 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
265
Forks
149
Avg merge
3h 3m
Merged PRs (30d)
2

Description

**Context**

Since we are targeting multiple platforms with several different defines (such as `#if UNITY_IOS` and `#if UNITY_ANDROID`) in our code base I would like to run tests while targeting these platforms. Currently only the `UNITY_LINUX_STANDALONE` define is set when running tests on an ubuntu runner.

This would make it so much easier to catch those simple compile mistakes when PR's lands too.

**Suggested solution**

I suggest that `-targetPlatform` is added as an option. This option would then require the unity project to have a static `RunTest` (or something similar) method also defined in a `-testMethod` option (similar to how `-buildMethod` works for [game-ci/unity-builder](https://game.ci/docs/github/builder)).

That testMethod would then need to look something like this (in an editor folder):
```
public static void RunTest()
{
var testRunnerApi = ScriptableObject.CreateInstance();
var filter = new Filter()
{
testMode = GetTestMode("-testPlatform"),
targetPlatform = GetBuildTarget("-targetPlatform")
};
testRunnerApi.Execute(new ExecutionSettings(filter));
}
```

**Additional details**

https://docs.unity3d.com/Packages/com.unity.test-framework@1.1/manual/extension-run-tests.html

Contributor guide

Open the contributing guide

Research direction

Start by tracing how the runner handles the existing -buildMethod option, then review Unity's extension-run-tests documentation for the proposed -targetPlatform and -testMethod flow. Done means tests can be invoked for selected Unity target platforms, including the corresponding platform defines, and the existing test-running behavior remains usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, typescript, unity
Domain
ci-cd, game-dev, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.