java - What sources of data/parameters should I use when Unit testing? -


i performing unit tests across large system, made of hundreds of different .java files, forming back-end.

in unit tests, should pass variables other methods (calling methods within test method) or test using values created/declared in test method?

i'm thinking should come values test method since these unit tests , trying test each method in isolation, i'm not this. need copy functions fetch said data unit tests?

generally speaking, should create values in test itself, better isolating system under test. there other kinds of tests, @james mentions, , can use junit integration tests unit tests. @ heart of junit testing unit testing, , proper unit tests isolate system under test.

update in response comment:

so example if have classes , b:

public class {   private b b = new b();    public void callb() {     b.process(17);     b.process(22);   } }  public class b {   public void process(int n) {     // stuff n   } } 

your test class b instantiate own b , call b.process(17) , b.process(22) without reference a, nor need subclass a. in order test in isolation b need kind of mocking mechanism replace b mock. such test use mock verify b.process had been called 17 , 22, not worrying happened consequence of calls.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -