java - Test a method without initialize the class -


i'm new unit testing, i'm wondering if there way test method without initializing class. reason i'm asking because there lot of object passing in constructor meaning lot of mocking stubbing while thorough check methodtotest seems not use object attribute. it's not code otherwise method converted static.

class exampleclass {    public exampleclass(firstclass fc, secondclass sc, thirdclass tc) {}     public void methodtotest(fourthclass foc) {} } 

you have options here:

  • make method static don't need reference actual object. work if method not need state of exampleclass (i.e. needs passed in method arguments).
  • extract method class (perhaps using method object pattern) that's easier test on own. refactoring called replace method method object.

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -