Unity自动化测试工具Automated QA2----调用代码

上一篇中讲解了自动化测试工具的基础用法,但是基础用法中无法实现键盘的监控,也就是无法监听输入,而且灵活度也有所欠缺。不过官方提供了另一套工具可以直接与代码交互~

用法很简单
1.点击Automated QA > Experimental > Create Automated Run也可以在文件夹中右键创建,创建完成后如下:
Unity自动化测试工具Automated QA2----调用代码_第1张图片
界面很简洁,就是一个结束时退出的选项和一个空的List。
2.添加list内容可以看到一些插件内置的调用方法,这里先略过
3.要与脚本交互就需要去写脚本,如下就是一个简单的查找到输入框输入账号密码的脚本

using System;
using Unity.AutomatedQA;
using UnityEngine;
using UnityEngine.UI;

[Serializable]
public class EeveeAutomatorConfig : AutomatorConfig
{
    public string id = "Eevee";
    public string password = "testpassword";
}

public class EeveeAutomator : Automator
{
    public override void BeginAutomation()
    {
        base.BeginAutomation();
        
        GameObject.Find("IDInputField").GetComponent().text = config.id;
        GameObject.Find("PasswordInputField").GetComponent().text = config.password;
        
        EndAutomation();
    }
}

4.脚本到位之后,就可以看到List中可以选择脚本了
Unity自动化测试工具Automated QA2----调用代码_第2张图片
5.点开下拉框可以自定义参数
Unity自动化测试工具Automated QA2----调用代码_第3张图片
6.设置好后点击Run即自动运行
Unity自动化测试工具Automated QA2----调用代码_第4张图片
这里要注意的一点是,当前版本(0.6.1)运行一次后会在场景中遗留一个StartAutomatedQAFromEditor物体,如果不删除此物体点击Unity自身的运行按钮会自动运行最近的config,因此每次运行完成后需要手动删除此物体~

你可能感兴趣的:(unity,测试工具,unity)