FreeCAD_SheetMetal icon indicating copy to clipboard operation
FreeCAD_SheetMetal copied to clipboard

Unit Tests to catch regressions introduced in development (either in master or in this repo)

Open luzpaz opened this issue 5 years ago • 5 comments

Can we discuss a way to run some unittests that catch possible regressions in this awesome addon. Case in point: https://forum.freecadweb.org/viewtopic.php?f=3&t=11303&p=361751#p361751

I guess I should open a ticket in FreeCAD-addons requesting a tutorial on how to write a unit test and ask Addon authors/FC-community to do so for addons.

luzpaz avatar Jan 19 '20 12:01 luzpaz

addon unit test tutorial: +1

shaise avatar Jan 19 '20 13:01 shaise

Absolutely necessary. #122 wouldn't exist if there were appropriate unit tests.

Moreover, unit tests would greatly help cleaning up the existing code. I would terrify if I start some cleanup because there is always a possibility to mess up the serious calculations.

ceremcem avatar Jun 09 '20 09:06 ceremcem

Ping @luzpaz

Is there any clear instructions about writing unit tests?

ceremcem avatar Dec 09 '20 17:12 ceremcem

@ceremcem not that I know of off hand, sorry. Hope someone wrote some documentation for it. But if not, then it would be old-fashion look at the pre-exisiting unit-tests in the core workbenches for orientation + asking on the forum

luzpaz avatar Dec 09 '20 20:12 luzpaz

I would like to start with defining how it should be (according to me, of course):

  1. Start recording a macro.
  2. Create a part from scratch or load it from a file.
  3. Perform relevant operations.
  4. Stop the macro recording.
  5. Create a Spreadsheet named Tests that will hold the expected values (lengths, angles etc.). It should contain "Description" (optional), "Expected" and "Observed" columns. Expected column should be hard coded and Observed column will be calculated by a formula.
  6. Use another macro, named "Test.FCMacro", which will simply "Compare the Expected and Observed column values in the Tests Spreadsheet.

This is how I expect to create a test for any workbench.

In order to execute tests:

  1. Execute FreeCAD by passing the relevant macro (and supply the file if a file is used) and the Test.FCMacro as arguments. I expect FreeCAD to execute first macro, recreate the values, and then execute Test.FCMacro, return the output of Test.FCMacro.

How does it sound?

ceremcem avatar Dec 14 '20 11:12 ceremcem