Unit Testing / TDD

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Unit Testing / TDD

Post by FreddyFreddy »

Looking to set up unit testing in IDE to assist during development.

Any hints / ideas / suggestions?

(I know there is functional testing in FC testing workbench, but that's not the same thing).
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

Nobody? Really?
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Unit Testing / TDD

Post by adrianinsaval »

What constitutes unit testing and why are the current test not considered unit tests? I thought that was what they are called.
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

You might want to look up Kent Beck, Martin Fowler, Uncle Bob Martin, Ian Cooper, just to name a few. Things have changed a bit since 1995.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unit Testing / TDD

Post by wmayer »

Here is a video how to do it with QtCreator: https://www.youtube.com/watch?v=N4pvvCToogM
and documentation: https://doc.qt.io/qtcreator/creator-autotest.html
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Unit Testing / TDD

Post by adrianinsaval »

FreddyFreddy wrote: Tue Jun 14, 2022 7:32 am You might want to look up Kent Beck, Martin Fowler, Uncle Bob Martin, Ian Cooper, just to name a few. Things have changed a bit since 1995.
So I ask you about a concept I'm not familiar with and you tell me to go learn about a bunch of dudes instead of the actual subject, weird but ok :?
I'm an amateur when it comes to coding and I was born in 1995 so I don't have any old-school bias that you have to dismantle.
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

adrianinsaval wrote: Tue Jun 14, 2022 9:20 pm So I ask you about a concept I'm not familiar with and you tell me to go learn about a bunch of dudes instead of the actual subject
No offence intended, but this "bunch of dudes" do a much better job of explaining than I ever could.

One definition from the dudes is "legacy code is code that does not have tests".

To have useful tests you have to have code broken into clean (SOLID principles etc) manageable chunks.

I am struggling with FreeCAD being largely old code that has not been updated much in the way the "bunch of dudes" would recommend. Huge files (eg 5000 lines) containing multiple classes and behaviours, macros all over the place, language features that have not been updated in many years, etc etc. Quite brittle and hence difficult to work on.

Study the "bunch of dudes" and you'll understand. They have good books, and lots of YouTube.
User avatar
chennes
Veteran
Posts: 3879
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Unit Testing / TDD

Post by chennes »

@adrianinsaval I suggest starting with Bob Martin's "Clean Code" - https://www.amazon.com/Clean-Code-Handb ... 132350882/ . It's well-written and lays out the case for this style of development quite nicely.

Anyway, no one is going to disagree that there is significant room for improvement to our codebase, and that any refactoring effort probably needs to begin with making sure we have adequate test coverage of the affected code. What IDE are you working with?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
FreddyFreddy
Posts: 176
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

chennes wrote: Wed Jun 15, 2022 12:26 amWhat IDE are you working with?
Not sure if you meant that at @adrianinsaval or me, but anyway, I have been using CLion which is great except it is sloooooow due to inspections, trying qt per Werner's suggestion - having trouble configuring cmake but it is early days.

Re Testing: Not a trivial task as the existing code has to be broken down into units of behaviour. Am more than happy to be involved in discussions as to how that might proceed.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Unit Testing / TDD

Post by wmayer »

On YT there are several videos with Robert C. Martin (aka Uncle Bob) and in the first video it's mainly about clean code. In further videos in this series also the concepts of TDD are explained.
Post Reply