Can CodePro Generate testCases for Private methods

CodePro AnalytiX (Audit & Test), includes over 1000 audit rules and metrics, JUnit test generation & editing, code coverage, and duplicate code analysis

Moderators: gnebling, jwren, Eric Clayberg, Dan Rubel, Brian Wilkerson, dcarew

Can CodePro Generate testCases for Private methods

Postby subbu » Thu May 22, 2008 12:59 am

Hi,

Can CodePro Generate testCases for Private methods ?

if answer Yes,then tell me how can i generate testCases for private methods?

if No,then give me suggestion on that(how can i generate testCases for private methods).

Is it limitation of CodePro??


if it is limitation, then ,How can i improve my class coverage percentage when i have a class whch contain Private methods?


thanks
subbu
subbu
 
Posts: 4
Joined: Sun May 18, 2008 11:26 pm

Re: Can CodePro Generate testCases for Private methods

Postby Brian Wilkerson » Wed May 28, 2008 11:13 am

Subbu,

CodePro does not currently support directly testing private methods because the common wisdom in the testing community seems to say that you shouldn't do this.

You should be able to execute all of the code in a private method by manually creating test methods that carefully control the state it uses (field values, parameter values, etc.) before invoking the non-private methods from which it is invoked. If you can't, then it's possible that the method is more general than it should be. However, I'm guessing that that's not the reason for the problem you're experiencing.

I realize that you don't want to manually create test method, but it's possible that this same technique could be used to improve coverage with generated tests. Essentially, the answer is probably to create a factory class that returns an instance of the class under test that is configured correctly to exercise the portions of the private methods that are not currently being executed. You can get more information about factory classes here:

http://downloads.instantiations.com/CodeProDoc/integration/latest/docs/doc/features/junit/test_case_generation.html#FactoryClasses
Brian Wilkerson
Google, Inc.
http://www.google.com
Brian Wilkerson
Moderator
 
Posts: 32
Joined: Fri Apr 28, 2006 9:37 am


Return to CodePro AnalytiX & PlusPak. EclipsePro Audit & Test

Who is online

Users browsing this forum: No registered users and 1 guest