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 to Return "String"
What Happens If a JUnit Test Method Is Declared to Return "String"?
✍: FYICenter.com QA Team
If a JUnit test method is declared to return "String", the compilation will pass ok. But the execution will fail. This is decause JUnit requires that all test methods must be declared to return "void". For example:
type HelloTestNonVoid.java import org.junit.Test; import static org.junit.Assert.*; // by FYICenter.com public class HelloTestNonVoid { @Test public String testHello() { String message = "Hello World!"; assertEquals(12, message.length()); return message; } } javac -cp junit-4.4.jar HelloTestNonVoid.java java -cp .;junit-4.4.jar org.junit.runner.JUnitCore HelloTestNonVoid JUnit version 4.4 .E Time: 0 There was 1 failure: 1) initializationError0(HelloTestNonVoid) java.lang.Exception: Method testHello should be void at org.junit.internal.runners.MethodValidator.validateTe at org.junit.internal.runners.MethodValidator.validateIn at org.junit.internal.runners.MethodValidator.validateMe at org.junit.internal.runners.JUnit4ClassRunner.validate at org.junit.internal.runners.JUnit4ClassRunner.<init>(J at sun.reflect.NativeConstructorAccessorImpl.newInstance at sun.reflect.NativeConstructorAccessorImpl.newInstance at sun.reflect.DelegatingConstructorAccessorImpl.newInst at java.lang.reflect.Constructor.newInstance(Constructor at org.junit.internal.requests.ClassRequest.buildRunner( at org.junit.internal.requests.ClassRequest.getRunner(Cl at org.junit.internal.requests.ClassesRequest.getRunner( 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, 5131👍, 0💬
Popular Posts:
Can Multiple Cursors Being Opened at the Same Time? - Oracle DBA FAQ - Working with Cursors in PL/SQ...
How To Control White Spaces between Table Cells? - XHTML 1.0 Tutorials - Understanding Tables and Ta...
What's the output of the following program? And why? #include main() { typedef union { int a; char b...
What is a measure in OLAP ? Measures are the key performance indicator that you want to evaluate. To...
How can you check to see whether a symbol is defined? You can use the #ifdef and #ifndef preprocesso...