I am working in C # and trying to figure out which unit test framework (MSTest, Nunit, Xunit) is used for the best approach to data-based testing methodology. I have some experience testing modules, but only with very simple functions. The function that I would like to apply unit tests is given below, as well as my solution and the form of the desired solution.
Unit Test Function
Point3D GetIntersectionPoint(List<Point3D> line1, List<Point3D> line2)
Returns a three-dimensional point (x, y, z) from two lines of arbitrary length and segments (assuming that they intersect at one point). We can say that all you need to check is a simpler function:
Point3D GetIntersectionPointSimple(LineSegment segment1, LineSegment segment2)
Where "LineSegment" is one segment of a straight line. However, I want to catch a case with several intersections, and I am interested in a solution, since it is quite general.
Attempt to solve
In MSTest, it’s easy to get a row of data from a data source, and so I had the following in a CSV file:
LineA LineB IntersectionPoint
0,0;1,0;2,0 1.5,1;1.5,0;1.5,-1 0,1.5
If individual points are separated by a ';' and the coordinates (x, y) are limited by the character ','. This example is in 2D for brevity only.
With this, you can read on each line, for example:
TestContext.DataRow["LineA"].ToString()
And then analyze it to get the list of points you need. This could be verified, for example:
Assert.AreEqual(parsedIntersectionPoint, GetIntersectionPoint(parsedLine1, parsedLine2))
This, however, seems rather confusing.
Desired Solution
Ideally, a solution to this problem would satisfy the following:
- Simple data addition (for example, a serialized object, ease of manual entry, as in the CSV approach)
- ( , CSV )
- , CSV, XML JSON.
, "" , , , "".
!