Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Issue with ArgumentException in Unity Test Framework Editor Mode

Discussion in 'Testing & Automation' started by Revitie, Dec 11, 2023.

  1. Revitie

    Revitie

    Joined:
    Feb 1, 2023
    Posts:
    1
    Hello, I am encountering the following error while using Unity's Test Framework:

    Code (Boo):
    1. ArgumentException: An item with the same key has already been added. Key:
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <787acc3c9a4c471ba7d971300105af24>:0)
    3. System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <787acc3c9a4c471ba7d971300105af24>:0)
    4. System.Linq.Enumerable.ToDictionary[TSource,TKey] (System.Collections.Generic.List`1[T] source, System.Func`2[T,TResult] keySelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) (at <dab7f68612224ba3ae40f651d44f9d4c>:0)
    5. System.Linq.Enumerable.ToDictionary[TSource,TKey] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) (at <dab7f68612224ba3ae40f651d44f9d4c>:0)
    6. System.Linq.Enumerable.ToDictionary[TSource,TKey] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector) (at <dab7f68612224ba3ae40f651d44f9d4c>:0)
    7. UnityEditor.TestTools.TestRunner.GUI.TestListGUI.get_ResultsByKey () (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/GUI/Views/TestListGUIBase.cs:44)
    8. UnityEditor.TestTools.TestRunner.GUI.TestListTreeViewDataSource.FetchData () (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/GUI/TestListTreeView/TestListTreeViewDataSource.cs:35)
    9. UnityEditor.IMGUI.Controls.TreeViewDataSource.ReloadData () (at <fe7039efe678478d9c83e73bc6a6566d>:0)
    10. UnityEditor.IMGUI.Controls.TreeViewController.ReloadData () (at <fe7039efe678478d9c83e73bc6a6566d>:0)
    11. UnityEditor.TestTools.TestRunner.GUI.TestListGUI.Reload () (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/GUI/Views/TestListGUIBase.cs:202)
    12. UnityEditor.TestTools.TestRunner.TestRunnerWindow+<>c__DisplayClass27_0.<StartRetrieveTestList>b__0 (UnityEditor.TestTools.TestRunner.Api.ITestAdaptor rootTest) (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/TestRunnerWindow.cs:162)
    13. UnityEditor.TestTools.TestRunner.Api.TestRunnerApi+<>c__DisplayClass8_0.<RetrieveTestList>b__0 (UnityEditor.TestTools.TestRunner.Api.ITestAdaptor testRoot) (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/Api/TestRunnerApi.cs:143)
    14. UnityEditor.TestTools.TestRunner.TestListJob.EditorUpdate () (at ./Library/PackageCache/com.unity.test-framework@1.1.33/UnityEditor.TestRunner/TestRunner/Utils/TestListJob.cs:31)
    15. UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <fe7039efe678478d9c83e73bc6a6566d>:0)
    16.  
    This issue occurs when opening the [Test Runner] window in Unity. I am using Unity version 2022.3.2f1 and the operating system is [windows 11].


    What I've tried so far:

    Completely reinstalling Unity (both Unity Hub and Unity Editor).
    Trying different versions of Unity.2022.3.10f1,2022.3.15f1
    Deleting the Library folder and restarting the project.
    Tested in a new project.
    Restarting my computer.
    Checking for updates on my operating system and drivers.

    Reason for uninstalling and reinstalling Unity, UnityHub
    1. Create a new completely empty project
    2. Open the test runner window.
    3.Open EditMode tab
    This also results in the same error




    I would greatly appreciate any advice or suggestions on this issue. If there are other steps or actions that I should try, I welcome those suggestions as well. Thank you in advance for your assistance.





    This post was created using automatic translation.
     

    Attached Files:

  2. ExtriW

    ExtriW

    Joined:
    Mar 12, 2024
    Posts:
    1
    I know that this thread is 1 year old now, but if anybody else struggles with the same issue, this can help.

    For me this bug appeared when I had added custom type's array to test class fixture. I tried restarting Unity, deleting almost all files (including those which were supposed to cause the error according to it's message), deleting Unity's cache. It didn't help. Only after I reimported everything (right click on Assets>Reimport All) the bug dissapeared.

    Edit:
    It almost worked. The bug disappeared only until the first time I edited my code. It seams that the Test Framework preserves it's entries in some external file (located outside of the project directory). They are not updated even when directory does not exists any more! I managed to finally fix it in debug mode. Below list of the steps I've taken:
    1. Attach Visual Studio to Unity
    2. Press error message in the Console window in Unity's editor
    3. It should open TestListGUIBase.cs class in your IDE. For me the error message is trigger by line 44
    4. Put break point in that line
    5. Now you should have access to the local variables. One that is causing troubles is "m_NewResultList". Edit it's value to "new List<TestRunnerResult>()"
    6. Now it should work fine
     
    Last edited: May 8, 2024