Visual Studio C#: Unable to run auto-generated IntelliTest code?

149 Views Asked by At

I have a test function in my project 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;
    }
}

When I click save on the IntelliTest UI:

enter image description here

It saves all the C# code that IntelliTest generated into a separate project called UnitAutoTestGeneration.Tests:

enter image description here

UnitTest1Test.cs (defines the function to be tested by referencing the original project 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 (contains the generated IntelliTest test code):

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);
}
    }
}

However, it seems that I am unable to run those generated tests, even when I click on the top menu bar Test -> Run All Tests, and clicking Run Tests on UnitTest1Test.add_abs_val_x_times.g.cs and UnitTest1Test, as on the left hand testing panel, it still shows the tests for the generated C# code as "Not run":

enter image description here

Furthermore, on the output, it states that nothing was built:

enter image description here

0

There are 0 best solutions below