VFPX / FoxUnit

Unit Testing in Visual FoxPro
25 stars 22 forks source link

Added support for theories #19

Closed cwollenhaupt closed 5 years ago

cwollenhaupt commented 5 years ago

Added support for theories. If a class contains an array with the same name as a test method plus "_data", then the test will be executed for every row in the array. Every value in a row is passed as a parameter to the test method. The following sample tests whether doubling a value yields the correct result for multiple test cases. The first column in the array is the value to be doubled, the second column is the expected result. The test is executed three times with different values. A new test case instance is created for every iteration.

  Dimension testTheory_Data[3,2]
  testTheory_Data[1,1] = 1
  testTheory_Data[1,2] = 2
  testTheory_Data[2,1] = 3
  testTheory_Data[2,2] = 6
  testTheory_Data[3,1] = 5
  testTheory_Data[3,2] = 10
  Procedure testTheory (tnValue, tnResult)
    this.AssertEquals (m.tnResult, 2*m.tnValue)
  EndProc

If one or more data points fails, the test is considered to have failed. The failure log lists the number and all values for every failed row.

Important: The previous test in the PRG file must end with ENDPROC or ENDFUNC. Otherwise, VFP considers the DIMENSION statement to be part of the previous test code.

cwollenhaupt commented 5 years ago

I've found two issues with my pull request and fixed those today.