have you considered creating a class that takes whose sole responsibility it to generate the SQL strings? ?Have the existing class rely on the SQL generator, then unit test the generator.
Hope that helps!
Graff
On Thursday, April 8, 2021, 05:18:08 PM EDT, Tony Vo <ttrung.vo@...> wrote:
Hi everyone,
I'm running into a scenario where I need to add extra condition in sql statement like this sqlStatement.sql("select id from table_a") if (conditionA == true) { ? ?sqlStatement.sql("AND table_a.column_a == 0") } // note there's many similar sqlStatement changes per other conditions as above....
The good news is that there's a good amount of integration tests surround this area. However, I feel like it's very rigid to make changes to sql statement based on some business conditions.
The other option I can think of is basically to move the condition to a higher level and then it's probably easier to unit test to check the code to execute different SQL statement based on the condition. Although I gotta say, the easiest change (least amount of effort is to make the above change and write integration tests for that change)
Moving the business condition to higher level is possible, but I would have more works to break some more dependencies and keeping the existing API unchanged as there're lots of methods calling this method.