Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Code coverage doesn't work with generics

Discussion in 'Testing & Automation' started by Suzak, Apr 1, 2023.

  1. Suzak

    Suzak

    Joined:
    Feb 20, 2017
    Posts:
    1
    Hello,

    I recently started unit testing in unity and tried to use the Code coverage package with it but i couldn't make it work with generic functions. If i re-write my function with a defined type there is no problem.

    I wanted to know if it's a known issue or is it just me who didn't do this correctly ?

    My function :
    Code (CSharp):
    1. public static bool HasIndex<T>(this T[] array, int index) => index.InRangeInclusive(0, array.Length - 1); // not marked as covered in coverage report
    My test :
    Code (CSharp):
    1. using NUnit.Framework;
    2.  
    3. public class ArrayTests
    4. {
    5.     private int[] arrayInt;
    6.  
    7.     [SetUp]
    8.     public void SetUp()
    9.     {
    10.         arrayInt = new int[5] { 0, 1, 2, 3, 4 };
    11.     }
    12.  
    13.     [Test]
    14.     public void HasIndex_Inferior0()
    15.     {
    16.         Assert.IsFalse(arrayInt.HasIndex(-1));
    17.     }
    18. }
    If i change my function by this it work fine :
    Code (CSharp):
    1. public static bool HasIndex(this int[] array, int index) => index.InRangeInclusive(0, array.Length - 1); // marked as covered in coverage report
     
  2. JuliusJ

    JuliusJ

    QA Minion of the month Unity Technologies

    Joined:
    May 20, 2015
    Posts:
    35
  3. JuliusJ

    JuliusJ

    QA Minion of the month Unity Technologies

    Joined:
    May 20, 2015
    Posts:
    35
    Hi @Suzak. Just wanted to let you know that earlier today we have released Code Coverage package 1.2.3 which fixes the generics issue. Generic methods should display correct coverage once again.