Unit Testing / TDD

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
adrianinsaval
Veteran
Posts: 2588
Joined: Thu Apr 05, 2018 5:15 pm

Re: Unit Testing / TDD

Post by adrianinsaval »

Thanks! I'll be looking into these
FreddyFreddy
Posts: 146
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

wmayer wrote: Tue Jun 14, 2022 10:22 am 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
I've loaded QtCtreator and got it going, but it really isn't as nice as CLion. Feels clunky. Having said that there are some features of QtCtreator that may be better adapted to test some qt based stuff.

The bigger question though is it there a way to begin transforming FreeCAD codebase to modern style. The cat and mouse question is that to safely refactor you need tests, but to get to having tests you have to refactor.

How does this discussion get started? Is there a will?
User avatar
doia
Posts: 177
Joined: Sat May 29, 2021 5:47 am
Location: Düsseldorf

Re: Unit Testing / TDD

Post by doia »

Oh yes, there is a will.

For unit tests I would suggest following some advice from the "Canonical Project Structure" initiative, see the part about tests: https://www.open-std.org/jtc1/sc22/wg21 ... html#tests

- Unit tests live as a source.test.cpp file next to the source.h and source.cpp files
- Functional and integration tests go into a separate tests/ folder
wmayer
Founder
Posts: 18621
Joined: Thu Feb 19, 2009 10:32 am

Re: Unit Testing / TDD

Post by wmayer »

I've loaded QtCtreator and got it going, but it really isn't as nice as CLion. Feels clunky. Having said that there are some features of QtCtreator that may be better adapted to test some qt based stuff.
Nobody is obliged to use QtCreator and I added links because I use this IDE on Linux. In the video and the tutorial it's explained how to set up the infrastructure for the testing framework and ideally it should work independent of the used IDE because it's all based on CMake.
FreddyFreddy
Posts: 146
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

wmayer wrote: Thu Jun 23, 2022 2:28 pm
it should work independent of the used IDE because it's all based on CMake.
Could you expand on that a bit?
wmayer
Founder
Posts: 18621
Joined: Thu Feb 19, 2009 10:32 am

Re: Unit Testing / TDD

Post by wmayer »

Could you expand on that a bit?
Not yet. I have to figure out first how to set it up.
FreddyFreddy
Posts: 146
Joined: Wed Mar 09, 2022 3:15 am
Location: Oz

Re: Unit Testing / TDD

Post by FreddyFreddy »

I guess Cmake will be involved in setting up the test environment as tests must be compiled.

The greater difficulty I see is to have code under test that is a unique unit of behaviour (eg class etc), dependancies well defined, pref injected via constructor (inverted) via interfaces so that service objects can be easily mocked. Macros, inheritance, dependencies, wandering state, multiple responsibilities, contrive to make unit testing extremely difficult or impossible. Individual tests must be very focused and execute very fast, as there will be loads of them and they will be run frequently during refactoring to identify problems early.

So far I am overwhelmed by how much change (refactoring) might be required to the codebase just to make a start. The python interface frightens me too.
Post Reply