Java Doc for TestCase.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » i3test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.i3test 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.sun.midp.i3test.TestCase

All known Subclasses:   javax.microedition.lcdui.TestCommandSorting,  com.sun.midp.services.TestSystemServiceRequest,  com.sun.midp.io.j2me.datagram.TestDatagramWouldBlock,  javax.microedition.sip.TestPushUtils,  com.sun.satsa.crypto.TestRC4,  javax.microedition.sip.TestSipRefreshHelper,  com.sun.midp.io.j2me.mms.TestMMSOpenClose,  javax.microedition.lcdui.TestItemLFImplLDoInternalLayout,  javax.microedition.rms.TestRecordStore,  com.sun.j2me.payment.TestTransactionStore,  com.sun.j2me.location.TestCriteria,  com.sun.midp.security.TestPermissions,  com.sun.midp.services.TestServiceRequestProtocol,  javax.microedition.sip.TestSipConnectionNotifier,  com.sun.midp.io.j2me.apdu.TestCad,  com.sun.midp.links.TestLinkPortal,  com.sun.midp.services.TestSystemServiceManager,  javax.microedition.lcdui.game.TestSprite,  com.sun.midp.links.TestKill,  com.sun.midp.test.TestSemaphore,  com.sun.midp.io.j2me.mms.TestMMSNumberOfSegments,  com.sun.midp.io.TestHttpUrl,  com.sun.midp.i3test.NamsTestCase,  com.sun.midp.rms.TestFileRscLimit,  com.sun.j2me.location.TestThreadSafety,  com.sun.midp.links.TestNamedLinkPortal,  com.sun.midp.io.j2me.sms.TestSMSOpenClose,  com.sun.midp.appmanager.TestUserNotification,  gov.nist.microedition.sip.TestSipDialogClient,  gov.nist.microedition.sip.TestSipClientCancel,  javax.microedition.sip.TestSipCommunication,  com.sun.midp.content.ExtendedTestCase,  javax.microedition.lcdui.TestStringItemNoLabelSizing,  com.sun.satsa.pki.TestPKI,  com.sun.midp.io.j2me.http.TestHttpHeaders,  com.sun.midp.links.TestEcho,  com.sun.midp.links.TestLinkMessage,  gov.nist.microedition.sip.TestSipClientSetHeader,  javax.microedition.lcdui.CustomItemTest,  com.sun.midp.suspend.TestDummy,  com.sun.j2me.location.TestLocationProvider,  javax.microedition.sip.TestOriginatingInvite,  javax.microedition.lcdui.DisplayManagerTest,  javax.microedition.sip.TestMultiNotifiers,  com.sun.j2me.location.TestLandmarkStore,  com.sun.midp.i3test.TestUtfReaders,  com.sun.midp.suspend.TestConnectionSuspend,  com.sun.midp.chameleon.input.TestNativeInputMode,  com.sun.midp.io.j2me.cbs.TestCBSOpenClose,  javax.microedition.sip.TestSubscribeNotify,  javax.microedition.sip.TestMessageAttachHeader,  com.sun.midp.io.j2me.storage.TestFileSystem,  com.sun.midp.main.TestMIDletControllerEventProducer,  com.sun.midp.services.TestSystemService,  com.sun.midp.io.j2me.cbs.TestCBS,  javax.microedition.sip.TestSipAddress,  javax.microedition.sip.SipHeaderBaseTest,  com.sun.midp.links.TestLink,  com.sun.midp.i3test.TestCompWildcard,  com.sun.midp.content.TestRegReadWrite,  com.sun.midp.links.TestLinkTransfer,  javax.microedition.lcdui.TestKeyConverter,  javax.microedition.lcdui.TestOne,  javax.microedition.lcdui.TestTextFieldInput,  javax.microedition.global.TestStringComparator,  javax.microedition.lcdui.TestIsShown,  javax.microedition.lcdui.Test6254765,  com.sun.midp.io.j2me.socket.TestNonblockingSocket,  javax.microedition.lcdui.TestDisplayPreempt,  javax.microedition.sip.TestRegisterTCP,  com.sun.midp.links.TestMultiple,  com.sun.midp.lcdui.TestDisplayFactory,  javax.microedition.lcdui.TestThree,  com.sun.midp.automation.TestSwitchMidlets,  javax.microedition.lcdui.TestNewSetCurrent,  com.sun.midp.links.TestRing,  com.sun.cardreader.TestGemplus1,  com.sun.midp.test.TestReflect,  javax.microedition.global.TestResourceManager,  com.sun.midp.util.FailTest,  com.sun.midp.io.j2me.storage.TestRandomAccessStream,  com.sun.midp.io.j2me.mms.TestMMSParseAddress,  com.sun.midp.events.TestHandleFatalError,  com.sun.cardreader.TestSlotFactory,  com.sun.midp.i3test.TestIsolateSynch,  javax.microedition.lcdui.TestTwo,  com.sun.midp.automation.TestAutoSuiteStorage,  javax.microedition.lcdui.TestCanvasSizing,  com.sun.midp.io.j2me.jcrmi.DataTest,  com.sun.midp.events.TestNativeEventPool,  com.sun.midp.io.j2me.sms.TestSMS,  com.sun.midp.services.TestSystemServiceConnectionListener,  gov.nist.microedition.sip.TestSipClientConnection,  com.sun.midp.events.TestEventQueue,  javax.microedition.global.TestFormatter,  gov.nist.microedition.sip.TestSipClientInitNotifyReq,  gov.nist.microedition.sip.TestSipDialogServer,  com.sun.midp.links.TestTransfer,  com.sun.midp.io.j2me.socket.TestPushRegistry,  javax.microedition.lcdui.TestStringItemSizing,  com.sun.j2me.location.TestLandmark,  javax.microedition.lcdui.TestSizeChanged,  javax.microedition.sip.TestPrack,  com.sun.satsa.utils.TestIA5,  javax.microedition.lcdui.TestGraphicsClipping,  com.sun.midp.io.j2me.socket.TestInterruptedIO,  javax.microedition.io.TestResourceLimit,  com.sun.midp.io.j2me.mms.TestMMSSendReceive,
TestCase
abstract public class TestCase (Code)
The main class for writing integrated internal interface (i3) tests. Tests should create a subclass of TestCase and implement the runTests() method. This method is responsible for running all of the tests. Tests consist of a test declaration followed by one or more assertions. The declaration is a call to the declare() method, which simply establishes a name for the set of assertions to follow. The assertions are made through calls to the assert*() family of methods. The framework considers it an error if any assertions are made prior to a call to declare(), or if there is a call to declare() with no subsequent calls to assert().

The TestCase class and its assert() methods are loosely based on the JUnit TestCase class. JUnit uses reflection to find test methods. Since reflection isn't present in CLDC, we need to have a runTests() method that calls them explicitly.

JUnit, in contrast to other test frameworks, doesn't return a result from each test. Instead, each test simply makes assertions, and only assertions that fail are flagged. The i3 tests follow the JUnit approach. For this reason, there is no pass() method one might expect to see corresponding to the fail() method.

While it's not a requirement, it's conventional for the TestCase subclass to reside in the same package as the code under test. This will allow the tests access to package-private variables and methods.

Each of the different assert() calls has an optional message parameter. This message is emitted only when the assertion fails and should be written with this in mind.

For "negative tests" that require an exception to be thrown, a suggested style is to record the fact that the correct exception was thrown in a boolean variable. This variable can then be tested using one of the assert() calls. This is probably preferable to placing calls to fail() in the midst of the test method. See testThree() in the example below.

The framework will catch any Throwable thrown by the tests and will log a message and count the occurrence as an error. This allows tests to be written more simply, because they can rely on the framework to catch everything. In support of this, the runTests() method has been defined with a 'throws Throwable' clause.

A general rule is that tests should run independently of each other. That is, tests should not leave any side effects that other tests rely on or that could cause them to fail. Typically, tests should create fresh objects for testing instead of reusing objects from other tests. If a test has any external side effects, such as creating threads or opening files, the test should be coded with a 'finally' clause that attempts to clean up after itself. See testFour() in the example below.

Example:


 import com.sun.midp.i3test;
 package java.lang;
 public class SampleTest extends TestCase {
 void testOne() {
 int i = 1 + 1;
 assertEquals("integer addition failed", 2, i);
 }
 void testTwo() {
 Object x = new Object();
 assertNotNull("Object constructor returned null", x);
 }
 void testThree() {
 StringBuffer sb;
 boolean caught = false;
 try {
 sb = new StringBuffer(-1);
 } catch (NegativeArraySizeException e) {
 caught = true;
 }
 assertTrue("no exception thrown", caught);
 }
 void testFour() {
 Thread thr = new Thread(...).start();
 try {
 // ...
 } finally {
 thr.interrupt();
 }
 }
 public void runTests() {
 declare("testOne");
 testOne();
 declare("testTwo");
 testTwo();
 declare("testThree");
 testThree();
 declare("testFour");
 testFour();
 }
 }
 


Field Summary
static  intcurrentNumAsserts
    
static  StringcurrentTest
    
static  TestCasecurrentTestCase
    
static  interrorAssertWithoutTest
    
static  interrorClassNotFound
    
static  interrorConstructorException
    
static  interrorNoTests
    
static  interrorNotTestCase
    
static  interrorTestRunThrows
    
static  interrorTestWithoutAssert
    
static  booleantokenEnabled
    
static  inttotalAsserts
    
static  inttotalCases
    
static  inttotalFailures
    
static  inttotalTests
    
static  booleanverbose
    

Constructor Summary
public  TestCase()
     Constructs a TestCase.

Method Summary
public  voidassertEquals(Object expected, Object actual)
     Asserts that two objects are equal according to the equals() method.
public  voidassertEquals(String message, Object expected, Object actual)
     Asserts that two objects are equal according to the equals() method.
public  voidassertEquals(int expected, int actual)
     Asserts that two integer values are equal.
public  voidassertEquals(String message, int expected, int actual)
     Asserts that two integer values are equal.
public  voidassertFalse(boolean condition)
     Asserts that condition is false.
public  voidassertFalse(String message, boolean condition)
     Asserts that condition is false.
public  voidassertNotNull(Object object)
     Asserts that the object reference is not null.
public  voidassertNotNull(String message, Object object)
     Asserts that the object reference is not null.
public  voidassertNotSame(Object expected, Object actual)
     Asserts that two references do not point to the same object, using the == operator.
public  voidassertNotSame(String message, Object expected, Object actual)
     Asserts that two references do not point to the same object, using the == operator.
public  voidassertNull(Object object)
     Asserts that the object reference is null.
public  voidassertNull(String message, Object object)
     Asserts that the object reference is null.
public  voidassertSame(Object expected, Object actual)
     Asserts that two references point to the same object, using the == operator.
public  voidassertSame(String message, Object expected, Object actual)
     Asserts that two references point to the same object, using the == operator.
public  voidassertTrue(String message, boolean condition)
     Tests the assertion that the boolean condition is true. If the condition is true, this method simply updates some statistics and returns.
public  voidassertTrue(boolean condition)
     Asserts that condition is true.
static  voidcleanup()
     Cleanup after running a test.
static  StringcurrentTestCaseName()
     Return the name of the current test case.
public  voiddeclare(String testName)
     Declares that the set of assertions that follow this call belong to a test named testName.
public  voidfail()
     Signals an unconditional assertion failure.
public  voidfail(String message)
     Signals an unconditional assertion failure.
protected  SecurityTokengetSecurityToken()
     Gets the system's internal security token.
protected  booleangetVerbose()
     Reads the verbose flag.
public  voidinfo(String s)
     If in verbose mode, print information.
static  voidp(String s)
     Print the string.
static  voidperror(int nerr, String errstr)
     Print the number of errors with the category.
static  voidreport()
    
static  voidreset()
     Reset the counters of all errors and exceptions.
static  voidrunTestCase(String testCaseName)
     Run the named test case.
abstract public  voidrunTests()
     Runs all the tests for this TestCase.
static  voidsetVerbose(boolean v)
     Set the verbose output flag.

Field Detail
currentNumAsserts
static int currentNumAsserts(Code)



currentTest
static String currentTest(Code)



currentTestCase
static TestCase currentTestCase(Code)



errorAssertWithoutTest
static int errorAssertWithoutTest(Code)



errorClassNotFound
static int errorClassNotFound(Code)



errorConstructorException
static int errorConstructorException(Code)



errorNoTests
static int errorNoTests(Code)



errorNotTestCase
static int errorNotTestCase(Code)



errorTestRunThrows
static int errorTestRunThrows(Code)



errorTestWithoutAssert
static int errorTestWithoutAssert(Code)



tokenEnabled
static boolean tokenEnabled(Code)



totalAsserts
static int totalAsserts(Code)



totalCases
static int totalCases(Code)



totalFailures
static int totalFailures(Code)



totalTests
static int totalTests(Code)



verbose
static boolean verbose(Code)




Constructor Detail
TestCase
public TestCase()(Code)
Constructs a TestCase. Since TestCase is an abstract class, this constructor is called only at the time a TestCase subclass is being constructed.




Method Detail
assertEquals
public void assertEquals(Object expected, Object actual)(Code)
Asserts that two objects are equal according to the equals() method.
Parameters:
  expected - an object containing the expected value
Parameters:
  actual - an object containing the actual value



assertEquals
public void assertEquals(String message, Object expected, Object actual)(Code)
Asserts that two objects are equal according to the equals() method. Two null references are considered to be equal.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  expected - an object containing the expected value
Parameters:
  actual - an object containing the actual value



assertEquals
public void assertEquals(int expected, int actual)(Code)
Asserts that two integer values are equal.
Parameters:
  expected - the expected value
Parameters:
  actual - the actual value



assertEquals
public void assertEquals(String message, int expected, int actual)(Code)
Asserts that two integer values are equal.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  expected - the expected value
Parameters:
  actual - the actual value



assertFalse
public void assertFalse(boolean condition)(Code)
Asserts that condition is false.
Parameters:
  condition - the condition asserted to be false



assertFalse
public void assertFalse(String message, boolean condition)(Code)
Asserts that condition is false.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  condition - the condition asserted to be false



assertNotNull
public void assertNotNull(Object object)(Code)
Asserts that the object reference is not null.
Parameters:
  object - the reference to be tested



assertNotNull
public void assertNotNull(String message, Object object)(Code)
Asserts that the object reference is not null.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  object - the reference to be tested



assertNotSame
public void assertNotSame(Object expected, Object actual)(Code)
Asserts that two references do not point to the same object, using the == operator.
Parameters:
  expected - a reference to the expected object
Parameters:
  actual - a reference to the actual object



assertNotSame
public void assertNotSame(String message, Object expected, Object actual)(Code)
Asserts that two references do not point to the same object, using the == operator.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  expected - a reference to the expected object
Parameters:
  actual - a reference to the actual object



assertNull
public void assertNull(Object object)(Code)
Asserts that the object reference is null.
Parameters:
  object - the reference to be tested



assertNull
public void assertNull(String message, Object object)(Code)
Asserts that the object reference is null.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  object - the reference to be tested



assertSame
public void assertSame(Object expected, Object actual)(Code)
Asserts that two references point to the same object, using the == operator.
Parameters:
  expected - a reference to the expected object
Parameters:
  actual - a reference to the actual object



assertSame
public void assertSame(String message, Object expected, Object actual)(Code)
Asserts that two references point to the same object, using the == operator.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  expected - a reference to the expected object
Parameters:
  actual - a reference to the actual object



assertTrue
public void assertTrue(String message, boolean condition)(Code)
Tests the assertion that the boolean condition is true. If the condition is true, this method simply updates some statistics and returns. If the condition is false, the failure is noted and the message is emitted, along with an indication of the current TestCase and the name of the test currently being run. The message string should be phrased in a way that makes sense when the test fails. See the example in the class documentation.
Parameters:
  message - the message to be emitted if the assertion fails
Parameters:
  condition - the condition asserted to be true



assertTrue
public void assertTrue(boolean condition)(Code)
Asserts that condition is true.
Parameters:
  condition - the condition to be tested



cleanup
static void cleanup()(Code)
Cleanup after running a test.



currentTestCaseName
static String currentTestCaseName()(Code)
Return the name of the current test case. the name of the class for the current test case.



declare
public void declare(String testName)(Code)
Declares that the set of assertions that follow this call belong to a test named testName. The framework considers it an error if no calls to any of the assert() methods follow a call to declare().
Parameters:
  testName - the name of the test



fail
public void fail()(Code)
Signals an unconditional assertion failure.



fail
public void fail(String message)(Code)
Signals an unconditional assertion failure.
Parameters:
  message - the message to be emitted, explaining the failure



getSecurityToken
protected SecurityToken getSecurityToken()(Code)
Gets the system's internal security token. This is useful for testing sensitive interfaces that require a security token parameter. This returns a valid security token only when called within the context of a call to runTests() inside a TestCase. At other times it will throw a SecurityException. the internal security token
throws:
  SecurityException - if not called from within runTests()



getVerbose
protected boolean getVerbose()(Code)
Reads the verbose flag. true if in verbose mode



info
public void info(String s)(Code)
If in verbose mode, print information.



p
static void p(String s)(Code)
Print the string.
Parameters:
  s - the string to print on a new line.



perror
static void perror(int nerr, String errstr)(Code)
Print the number of errors with the category.
Parameters:
  nerr - the number of errors in the category
Parameters:
  errstr - the description of the errors



report
static void report()(Code)



reset
static void reset()(Code)
Reset the counters of all errors and exceptions.



runTestCase
static void runTestCase(String testCaseName)(Code)
Run the named test case.
Parameters:
  testCaseName - the class name of the test case



runTests
abstract public void runTests() throws Throwable(Code)
Runs all the tests for this TestCase. This is an abstract method that must be implemented by the subclass. The implementation of this method should run all of the tests provided in this TestCase. This method can also be used to initialize and tear down any state that might need to be shared among all the tests.

A suggested organization is to have runTests() alternate calling declare() and an internal method that implements the test. One could write the declare() method as part of the internal test method, but consolidating all calls in runTests() makes it a little easier to ensure that each test has its own call to declare(). See the example in the class documentation.




setVerbose
static void setVerbose(boolean v)(Code)
Set the verbose output flag.
Parameters:
  v - true to enable verbose output



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.