UTF测试:Running a test in a Unity project

准备

  1. 安装Test Framework包,导入Samples包
    在这里插入图片描述
  2. 打开文档学习

Exercise 1:Runing Tests

  1. 打开测试窗口:Window->General->Test Runner
  2. 创建测试程序集:右键Create->Testing->Tests Assembly Folder
  3. 创建测试脚本:Create > Testing > C# test script
  4. 测试程序集添加引用
    在这里插入图片描述

待测试脚本

namespace MyExercise_1
{
    public static class MyMath
    {
        public static int Add(int a, int b)
        {
            return a + b;
        }
    
        //wrong
        public static int Subtract(int a, int b)
        {
            return a - b + a; // The code is wrong. Let's see if your test can see that.
        }

        //correct
        public static int Subtract2(int a,int b)
        {
            return a - b;
        }
    }
}

测试脚本

using NUnit.Framework;
namespace Tests
{
    public class NewTestScript
    {
        [Test]
        public void NewTestScriptSimplePasses()
        {
        	//参数一 期望的结果
        	//参数二 真实的结果
            Assert.AreEqual(3, MyExercise_1.MyMath.Add(1, 2));
        }

        [Test]
        public void NewTestScriptSimplePasses2()
        {
            Assert.AreEqual(1, MyExercise_1.MyMath.Subtract(2, 1));
        }

        [Test]
        public void NewTestScriptSimplePasses3()
        {
            Assert.AreEqual(1, MyExercise_1.MyMath.Subtract2(2, 1));
        }
    }
}

测试

在这里插入图片描述
选择一个测试,右键Run即可;测试通过,显示绿色;测试失败,显示红色。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值