c++ - How to decide on what unit tests to create for a rules-based system -


i've been reading lot unit testing , considering using c++ , tdd first time. problem have of examples see in creating tests, appear trivial when think how begin writing tests project i'm develop. may i'm missing point of unit tests, please let me know if case here.

it's easy understand function that, example checks prime numbers. has simple input (the number test) , simple output (true or false). easy understand , create unit test here.

now, let's take, example, firewall application has configuration file of rules , evaluation engine evaluate rules in particular order, specific inputs; details of network packet such ip, subnet, port, domain etc.

without writing unit tests, think start writing parser parse rules config file classes , write rules engine compare given network packets rules in classes, stepping through rules in order parsed until match found.

unit tests , tdd states before writing code, tests fail should written first. therefore, in case of firewall project, start writing tests check parsing of file creating mock file provide specific set of rules, or testing reading of file, not recommended unit tests, rather integration tests? if tests done here, should tested?

also, how 1 think writing tests such rules engine evaluate rules? if details of network packet input, output whether or not packet accepted, rejected or ignored. such test identical rules engine doing, how broken down small "unit" tests?

you need tests parser. given input string, make sure correct rule object comes out. not access files, because parser should not tightly coupled file i/o.

you need tests every rule. make sure rule gives results want given packets. important part; sure test edge cases thoroughly. don't want of these rules misbehave, because bombarded malicious input.

and need tests rule system. write simple test rules , use them make sure rule system correctly dispatches packets , acts on responses.

all of these can written before actual code.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -