1

我的项目中有一个测试功能UnitAutoTestGeneration

public static void add_abs_val_x_times(int val_to_add, int x, ref int num_to_add_to)
{
    if (val_to_add < 0)
    {
        val_to_add = -1 * val_to_add;
    }
    for (int i = 0; i < x; i++)
    {
        num_to_add_to += val_to_add;
    }
}

当我在 IntelliTest UI 上单击保存时:

在此处输入图像描述

它将 IntelliTest 生成的所有 C# 代码保存到一个名为的单独项目中UnitAutoTestGeneration.Tests

在此处输入图像描述

UnitTest1Test.cs(通过引用原始项目定义要测试的功能UnitAutoTestGeneration):

// <copyright file="UnitTest1Test.cs">Copyright ©  2021</copyright>

using System;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UnitAutoTestGeneration;

namespace UnitAutoTestGeneration.Tests
{
    [TestClass]
    [PexClass(typeof(UnitTest1))]
    [PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
    [PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
    public partial class UnitTest1Test
    {

        [PexMethod]
        public void add_abs_val_x_times(
            int val_to_add,
            int x,
            ref int num_to_add_to
        )
        {
            UnitTest1.add_abs_val_x_times(val_to_add, x, ref num_to_add_to);
            // TODO: add assertions to method UnitTest1Test.add_abs_val_x_times(Int32, Int32, Int32&)
        }
    }
}

UnitTest1Test.add_abs_val_x_times.g.cs(包含生成的 IntelliTest 测试代码):

using Microsoft.Pex.Framework.Generated;
using Microsoft.VisualStudio.TestTools.UnitTesting;
// <copyright file="UnitTest1Test.add_abs_val_x_times.g.cs">Copyright ©  2021</copyright>
// <auto-generated>
// This file contains automatically generated tests.
// Do not modify this file manually.
// 
// If the contents of this file becomes outdated, you can delete it.
// For example, if it no longer compiles.
// </auto-generated>
using System;

namespace UnitAutoTestGeneration.Tests
{
    public partial class UnitTest1Test
    {

[TestMethod]
[PexGeneratedBy(typeof(UnitTest1Test))]
public void add_abs_val_x_times130()
{
    int i = 0;
    this.add_abs_val_x_times(0, 0, ref i);
    Assert.AreEqual<int>(0, i);
}

[TestMethod]
[PexGeneratedBy(typeof(UnitTest1Test))]
public void add_abs_val_x_times993()
{
    int i = 0;
    this.add_abs_val_x_times(0, 1, ref i);
    Assert.AreEqual<int>(0, i);
}

[TestMethod]
[PexGeneratedBy(typeof(UnitTest1Test))]
public void add_abs_val_x_times776()
{
    int i = 0;
    this.add_abs_val_x_times(int.MinValue, 0, ref i);
    Assert.AreEqual<int>(0, i);
}

[TestMethod]
[PexGeneratedBy(typeof(UnitTest1Test))]
public void add_abs_val_x_times214()
{
    int i = 0;
    this.add_abs_val_x_times(0, 2, ref i);
    Assert.AreEqual<int>(0, i);
}
    }
}

但是,似乎我无法运行这些生成的测试,即使我单击顶部菜单栏 Test -> Run All Tests,然后单击 Run Tests onUnitTest1Test.add_abs_val_x_times.g.csUnitTest1Test,就像在左侧测试面板上一样,它仍然显示测试对于生成的 C# 代码为“未运行”:

在此处输入图像描述

此外,在输出中,它指出没有构建任何内容:

在此处输入图像描述

4

0 回答 0