02 Aug 2013, 8:53
Hey there
I am using CppUnit to perform unit testing in my projects. Though everything is quite straight forward most of the time, unit testing gets difficult or better say more complicated when it comes to classes that are initialized over xml.
Examples for this would be a classes inheriting from Logic::GraphPositionInstance or classes containing/being custom nodes (e.g. http://murlengine.com/forum/showthread.php?tid=36 ).
Another problem arises when I want to test methods that modify the UI in some way.
So far I helped myself by creating custom constructors to be used in test cases and initializing only the most necessary stuff in order for the tests to work.
When it comes to methods manipulating the UI, I used preprocessor commands to disable UI interactions.
Example:
So much for explaining my approach...
Now to my questions.
I am using CppUnit to perform unit testing in my projects. Though everything is quite straight forward most of the time, unit testing gets difficult or better say more complicated when it comes to classes that are initialized over xml.
Examples for this would be a classes inheriting from Logic::GraphPositionInstance or classes containing/being custom nodes (e.g. http://murlengine.com/forum/showthread.php?tid=36 ).
Another problem arises when I want to test methods that modify the UI in some way.
So far I helped myself by creating custom constructors to be used in test cases and initializing only the most necessary stuff in order for the tests to work.
When it comes to methods manipulating the UI, I used preprocessor commands to disable UI interactions.
Example:
void ToggleButton::OnSetToInactive()
{
Notify(Button::GetButtonId(), ToggleButton::Messages::SET_TO_INACTIVE);
#ifdef DRAW_GUI_ACTION
TextTextureNode->SetBackgroundColor(Color(133.0f, 133.0f, 133.0f, 0.0f));
ButtonNode->SetEnabled(false);
#endif
}
So much for explaining my approach...
Now to my questions.
- Is this is the correct/optimal way to perform unit testing with MURL?
- Would it be possible to also include methods that manipulate UI components into testing (e.g. SetBackgroundColor)?
- Are there any best practices or "dos and don'ts" you came across during your development?