java - location of specific function in Junit source -


junit 4.x not provide private methods have test methods generated them. looking in junit source code (downloaded github) enforced in code not able locate it. did find checks test methods public, looking either explicitly checks target class's methods' modifiers or otherwise omits or skips processing private methods of target class. know code might located?

addendum:

ok so, we've been having nice little chat on , here's what's been learned. suppose have class foo 2 methods, bar , baz, both private. ordinarily using combination of ide , junit4.x cannot make junit generate test stubs these methods on account of being private. rule "do not generate test stubs private methods" enforced @ level of ide , not part of junit per se.

so class this:

public class foo {     private void bar(){}      private void baz(){} } 

you can't generated:

public class footest{      @test     public void testbar(){}      @test     public void testbaz(){} } 

but if alter ide, leaving junit alone can test methods generated. note junit check in runner if methods marked @test public , refuse run them if they're not, that's different concern.

the actual check in frameworkmethod#validatepublicvoid(boolean, list<throwable>).

runner implementations extend parentrunner make call validate() in parentrunner constructor. validate() private delegates protected method implementations override called collectinitializationerrors(list<throwable>). blockjunit4classrunner's implementation calls validateinstancemethods(errors); (which deprecated, it's weird) ends calling method above.


confused edit:

i don't know you're asking anymore. there's nothing special junit. it's library. write java code has number of annotations make sense junit. junit cannot prevent writing code.

junit or (or ide) provide class has main method.

it gets executed so

java -cp <some class path> theclasswithmain <more arguments> 

just other java program.

the junit classes, ie. parentrunner, children, , others related, use reflection scan provided test classes. build test suite, ie. setup methods, test methods, tear down methods, thrown exception expectations, assertion expectations, etc.

the junit api has specific documentation allowed , isn't. can find javadoc here. @test example, says

the test annotation tells junit public void method attached can run test case.

this true regardless of ide.

remember, these not compile time checks, run time checks result of reflective analysis of code.

now, ide, whatever is, might have junit plugin these checks statically, ie. doing static analysis of code, not run time analysis. can because source code available.

if question ide behavior, you'll need specify ide you're using. if question how junit prevent private @test methods being run, answer above.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -