You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, to run unit tests for backend methods, without having to worry about code on the ModelClass side, I decided to template the backend classes. That way, I thought I could easily unittest backend and also use our current workflow (where we tell you what changes we want in ModelClassExt, and you implement them when possible in ModelClass).
Now, as I started writing unit tests, I've realized that though it is still possible to do so without any modifications, it is going to lead to a lot of extra code on the testing end. See this , this , and this if you'd like to learn why.
To me, the quickest fix looks like making all methods and functions in ModelClass non-static. And honestly, that sounds like a good code design decision even without considering testing. I mean, we are practically using ModelClass as an object. We have an initializing function, and we have a close() function. From what I can tell, the change should be easy as well.
find and replace static with virtual in model/modelclass.h (virtual functions help overload without issues)
Change any static function calls of ModelClass:: to this->
move initialization of database and db, query to constructor which would be ModelClass(std::string databaseFilePath)
On backend, we could even remove templating and take in the ModelClass object into the Controller's constructor. And similarly, we would replace T:: with this->modelObject.
Let me know what you think. I might be completely missing something.
The text was updated successfully, but these errors were encountered:
I have converted all the code in backend to the non-static version in the branch nonstatic. You can take a look at it. Let me know if you don't want to make the changes. Otherwise, let me know when you're free. We can work on changing the current ModelClass to this implementation together.
So, to run unit tests for backend methods, without having to worry about code on the ModelClass side, I decided to template the backend classes. That way, I thought I could easily unittest backend and also use our current workflow (where we tell you what changes we want in ModelClassExt, and you implement them when possible in ModelClass).
Now, as I started writing unit tests, I've realized that though it is still possible to do so without any modifications, it is going to lead to a lot of extra code on the testing end. See this , this , and this if you'd like to learn why.
To me, the quickest fix looks like making all methods and functions in ModelClass non-static. And honestly, that sounds like a good code design decision even without considering testing. I mean, we are practically using ModelClass as an object. We have an initializing function, and we have a close() function. From what I can tell, the change should be easy as well.
static
withvirtual
inmodel/modelclass.h
(virtual functions help overload without issues)ModelClass::
tothis->
db
,query
to constructor which would beModelClass(std::string databaseFilePath)
T::
withthis->modelObject.
Let me know what you think. I might be completely missing something.
The text was updated successfully, but these errors were encountered: