Categories:
.NET (961)
C (387)
C++ (185)
CSS (84)
DBA (8)
General (31)
HTML (48)
Java (641)
JavaScript (220)
JSP (109)
JUnit (31)
MySQL (297)
Networking (10)
Oracle (562)
Perl (48)
Perl (9)
PHP (259)
PL/SQL (140)
RSS (51)
Software QA (28)
SQL Server (5)
Struts (20)
Unix (2)
Windows (3)
XHTML (199)
XML (59)
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, 5124👍, 0💬
Popular Posts:
What does AddressOf operator do in background ? The AddressOf operator creates a delegate object to ...
.NET INTERVIEW QUESTIONS - Did VB6 support multi-threading ? While VB6 supports multiple single-thre...
How do I use forms? The basic syntax for a form is: <FORM ACTION="[URL]">...&l t;/FORM>Wh...
I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, ...
The object that contains all the properties and methods for every ASP.NET page, that is built is .. ...