Unit Test for a Static class with static dictionary in C#

  • Thread starter Thread starter Stick.Hello
  • Start date Start date
S

Stick.Hello

Guest
I am new to C# UT.


I have static class (requirement are strict).


public static class MyClass
{
public static readonly Dictionary<int, int> MyDictionary;

static MyClass()
{
MyDictionary = new Dictionary<int, int>();
}

public static void init(string filePath) // external file path which has key value pair
{
// Fill the dictionary
}

public static int GetValue(int key)
{
int value = -1;
//some conditional logic and then
return MyDictionary.TryGetValue(key, value);
}
}


How to do the unit test for this class and dictionary.

Continue reading...
 
Back
Top