Monkey Test Helper
Reference implementation that performs object-based Unity UI (uGUI) monkey tests and an API for custom implementation.
This library can use in runtime code because it does not depend on the Unity Test Framework.
Required Unity 2019 LTS or later.
Features
Monkey test reference implementation
Run a monkey test for uGUI (2D, 3D, and UI) elements.
Monkey.Run
method operates on randomly selected objects. It does not use screen points.
Usage:
[Test]
public async Task MonkeyTesting()
{
var config = new MonkeyConfig
{
Lifetime = TimeSpan.FromMinutes(2),
DelayMillis = 200,
SecondsToErrorForNoInteractiveComponent = 5,
};
await Monkey.Run(config);
}
Configurations in MonkeyConfig
:
- Lifetime: Running time
- DelayMillis: Delay time between operations
- SecondsToErrorForNoInteractiveComponent: Seconds to determine that an error has occurred when an object that can be interacted with does not exist
- TouchAndHoldDelayMillis: Delay time for touch-and-hold
- Random: Random generator
- Logger: Logger
Find and operate interactive uGUI elements API
InteractiveComponentCollector.FindInteractiveComponents
Returns interactive uGUI components.
If the argument is true, return only user-really reachable components (using the IsReallyInteractiveFromUser
method).
Usage:
[Test]
public void FindAndOperationInteractiveComponent()
{
var component = InteractiveComponentCollector.FindInteractiveComponents(true)
.First();
if (component.CanClick())
{
component.Click();
}
}
InteractiveComponent.IsReallyInteractiveFromUser
Returns true if the component is really reachable from the user.
Usage:
[Test]
public void FindAndOperationInteractiveComponent()
{
var component = InteractiveComponentCollector.FindInteractiveComponents(false)
.First();
if (component.IsReallyInteractiveFromUser() && component.CanClick())
{
component.Click();
}
}
Installation
You can choose from two typical installation methods.
Install via Package Manager window
- Open the Package Manager tab in Project Settings window (Editor > Project Settings)
- Click + button under the Scoped Registries and enter the following settings (figure 1.):
- Name:
package.openupm.com
- URL:
https://package.openupm.com
- Scope(s):
com.nowsprinting
andcom.cysharp
- Name:
- Open the Package Manager window (Window > Package Manager) and select My Registries in registries drop-down list (figure 2.)
- Click Install button on the
com.nowsprinting.test-helper.monkey
package
Note
Do not forget to addcom.cysharp
into scopes. These are used within this package.
Figure 1. Package Manager tab in Project Settings window.
Figure 2. Select registries drop-down list in Package Manager window.
Install via OpenUPM-CLI
If you installed openupm-cli, run the command below:
openupm add com.nowsprinting.test-helper.monkey
Add assembly reference
- Open your test assembly definition file (.asmdef) in Inspector window
- Add TestHelper.Monkey into Assembly Definition References
License
MIT License
How to contribute
Open an issue or create a pull request.
Be grateful if you could label the PR as enhancement
, bug
, chore
, and documentation
.
See PR Labeler settings for automatically labeling from the branch name.
How to development
Add this repository as a submodule to the Packages/ directory in your project.
Run the command below:
git submodule add https://github.com/nowsprinting/test-helper.monkey.git Packages/com.nowsprinting.test-helper.monkey
Warning
Required install packages for running tests (when adding to thetestables
in package.json), as follows:
- Unity Test Framework package v1.3 or later
- Test Helper package v0.1.1 or later
Release workflow
Run Actions > Create release pull request > Run workflow and merge created pull request. (Or bump version in package.json on default branch)
Then, Will do the release process automatically by Release workflow. And after tagging, OpenUPM retrieves the tag and updates it.
Do NOT manually operation the following operations:
- Create a release tag
- Publish draft releases