Answer the question
In order to leave comments, you need to log in
How to test a list in C# NUnit?
I never really understood this topic, but then it took me to test the list in the class.
There are several variants of the tests themselves, but they do not use the class as such, but test directly in themselves.
For example:
[Test]
public void test()
{
var expected = new List<int> { 1, 2, 3 };
var actual = new List<int> { 1, 2, 3 };
CollectionAssert.AreEqual(expected, actual); //1
Assert.AreEqual(expected, actual); //2
Assert.That(actual, Is.EqualTo(expected)); //3
}
public class listtest
{
private List<string> tlist = new List<string>();
//write
public void Write(string s)
{
tlist.Add(s);
}
//index elements
public string ReadElement(int i)
{
return tlist.ElementAt(i);
}
}
Answer the question
In order to leave comments, you need to log in
Your listtest class encapsulates a List in itself, there is no way you can get full access to it without providing it in the class.
Method names are strange, it is better to replace Write with Add.
The meaning is not clear, you have an adapter or a proxy. Determine the exact task of the class, perhaps there are already ready-made implementations.
According to the test, make a method that will return a copy of the internal list, let the copies be compared.
Read Rules for Using Arrays , Choosing Between Properties and Methods .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question