Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What Happens If a JUnit Test Method Is Declared as "private"
What Happens If a JUnit Test Method Is Declared as "private"?
✍: FYICenter.com QA Team
If a JUnit test method is declared as "private", the compilation will pass ok. But the execution will fail. This is decause JUnit requires that all test methods must be declared as "public". For example:
type HelloTestPrivate.java import org.junit.Test; import static org.junit.Assert.*; // by FYICenter.com public class HelloTestPrivate { @Test private void testHello() { String message = "Hello World!"; assertEquals(12, message.length()); } } javac -cp junit-4.4.jar HelloTestPrivate.java java -cp .;junit-4.4.jar org.junit.runner.JUnitCore HelloTestPrivate JUnit version 4.4 .E Time: 0 There was 1 failure: 1) initializationError0(HelloTestPrivate) java.lang.Exception: Method testHello should be public at org.junit.internal.runners.MethodValidator.validateTestMethod at org.junit.internal.runners.MethodValidator.validateInstanceMe at org.junit.internal.runners.MethodValidator.validateMethodsFor at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4C at org.junit.internal.runners.JUnit4ClassRunner.<init>(JUn at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeC at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Del at java.lang.reflect.Constructor.newInstance(Constructor.java:51 at org.junit.internal.requests.ClassRequest.buildRunner(ClassReq at org.junit.internal.requests.ClassRequest.getRunner(ClassReque at org.junit.internal.requests.ClassesRequest.getRunner(ClassesR at org.junit.runner.JUnitCore.run(JUnitCore.java:109) at org.junit.runner.JUnitCore.run(JUnitCore.java:100) at org.junit.runner.JUnitCore.runMain(JUnitCore.java:81) at org.junit.runner.JUnitCore.main(JUnitCore.java:44) FAILURES!!! Tests run: 1, Failures: 1
2008-01-24, 5433👍, 0💬
Popular Posts:
How To Avoid the Undefined Index Error? - PHP Script Tips - Processing Web Forms If you don't want y...
What is the value of this expression? +1-2*3/4 -0.5
What is cross page posting? By default, button controls in ASP.NET pages post back to the same page ...
How can I show HTML examples without them being interpreted as part of my document? Within the HTML ...
What are different properties provided by Objectoriented systems ? Following are characteristic’s of...