Unit test for a method that populates a dictionary from an API call I am building a unit test for a method that populates a dictionary from an API call (responding with JSON):

&lt;TestMethod()&gt; Public Sub GetListOfBadKPI_EmptyResponse_ReturnsEmptyDict()
        'Arrange
        Const scheduleName As String = "testSchedule"

        Const emptyResponseJSON As String = "{""data"":[{""r"":""N""}]}"
        Dim fakeResult As Data = JsonConvert.DeserializeObject(Of Data)(emptyResponseJSON)    
        Dim fakeServer As MockServer = New MockServer With {.ReturnData = fakeResult}

        Dim CalculationSchedule As CalculationSchedule = New CalculationSchedule(scheduleName, fakeServer)

        'Act
        Dim resultDictionary As Dictionary(Of String, Integer) =
        CalculationSchedule.GetDictionaryOfBadCalculation()

        'Assert
        Assert.IsTrue(resultDictionary.Count = 0)
    End Sub


The fake server is used to return any data I need for the test, without actually connecting with the API:

Public Class MockServer
    Implements IServer

    Public Property ReturnData As Data

    Public Function ExecuteQuery(query As String, Optional server As String = Nothing) As Data Implements IServer.ExecuteSQLQuery
        Return ReturnData
    End Function
End Class


This setup allows me to simulate API responses to test different cases.

However, I am not happy with the way it is done, mainly since JSON strings have a lot of quotes " and dealing with those in VB.NET is daunting, since you have to double them up, it makes copy-pasting difficult, and so on.

Moreover, it does not feel very 'professional' to do it like this.

How could I improve this unit test?
There is a better way than using a string, there is a Namespace that you can import called Json or System.Json

after you have imported this you have access to JsonValue Arrays which allows you to nest JavaScript Objects creating a JSON Document.

it actually looks like you are already using the Namespace to deserialize the string into an object, not sure why you aren't just creating the JSON Objects themselves. they are just collections of KeyValuePairs of Of String, JsonValue  (Dictionaries, Collections, or Enumerables)