Return-Path: X-Original-To: apmail-openjpa-commits-archive@www.apache.org Delivered-To: apmail-openjpa-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D3A82DF9A for ; Mon, 19 Nov 2012 19:45:12 +0000 (UTC) Received: (qmail 62524 invoked by uid 500); 19 Nov 2012 19:45:12 -0000 Delivered-To: apmail-openjpa-commits-archive@openjpa.apache.org Received: (qmail 62494 invoked by uid 500); 19 Nov 2012 19:45:12 -0000 Mailing-List: contact commits-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list commits@openjpa.apache.org Received: (qmail 62486 invoked by uid 99); 19 Nov 2012 19:45:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 19:45:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 19:45:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 73A2A2388AAA for ; Mon, 19 Nov 2012 19:44:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1411367 - /openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext Date: Mon, 19 Nov 2012 19:44:48 -0000 To: commits@openjpa.apache.org From: curtisr7@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121119194448.73A2A2388AAA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: curtisr7 Date: Mon Nov 19 19:44:47 2012 New Revision: 1411367 URL: http://svn.apache.org/viewvc?rev=1411367&view=rev Log: Update writing-test-cases-for-openjpa wiki page. Modified: openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext Modified: openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext URL: http://svn.apache.org/viewvc/openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext?rev=1411367&r1=1411366&r2=1411367&view=diff ============================================================================== --- openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext (original) +++ openjpa/site/trunk/content/writing-test-cases-for-openjpa.mdtext Mon Nov 19 19:44:47 2012 @@ -7,55 +7,54 @@ You are welcome to contribute new test c and guidelines on how to contribute new test case to OpenJPA repository of 2000 test cases spread across 400 classes. -{tip:title=Inherit from OpenJPA TestCases} -Unit Tests are *JUnit* Tests. The base JUnit test case implementation +## Inherit from OpenJPA TestCases +Unit Tests are **JUnit** Tests. The base JUnit test case implementation *org.junit.TestCase* has been extended to facilitate common initialization steps or configuration settings for unit testing OpenJPA. The inheritance hierarchy is: - - junit.framework.TestCase - +-- org.apache.openjpa.persistence.test.PersistenceTestCase - +-- org.apache.openjpa.persistence.test.SingleEMFTestCase - +-- org.apache.openjpa.persistence.test.SQLListenerTestCase - +
+        
+            junit.framework.TestCase
+               +-- org.apache.openjpa.persistence.test.PersistenceTestCase
+                   +-- org.apache.openjpa.persistence.test.SingleEMFTestCase
+            	  +-- org.apache.openjpa.persistence.test.SQLListenerTestCase
+        
+
As a test developer, you should inherit your test class from one of the extended TestCases. In general, *SingleEMFTestCase* is a good candidate to inherit from. If your test needs to analyze or count number of SQL statements, *SQLListenerTestCase* should be your choice. -{tip} - -{tip:title=Use correct name and package for test case and entity classes} -* Test case should be in a separate sub-package of -*org.apache.openjpa.persistence.** or -*org.apache.openjpa.persistence.jdbc.** -* Test case class names must start with "Test" e.g. *TestEagerFetch* +## Use correct name and package for test case and entity classes +* Test case should be in a separate sub-package of +*org.apache.openjpa.persistence.* **or** *org.apache.openjpa.persistence.jdbc.** +* Test case class names must start with "Test" e.g. **TestEagerFetch** * There are hundreds of testable entity classes. But if your test requires new entity classes, place them in the same package as that of the new Test cases. -{tip} -{tip:title=setUp() and tearDown()} -* OpenJPA TestCases augment the *setUp()* method to accept a list of + +## setUp() and tearDown()} +* OpenJPA TestCases augment the **setUp()** method to accept a list of arguments. In this list, you should specify: - ** the entity classes used by your test - ** the critical configuration properties - ** *CLEAR_TABLES* or *DROP_TABLES* : these are constants declared in + * the entity classes used by your test + * the critical configuration properties + * **CLEAR_TABLES** or **DROP_TABLES** : these are constants declared in the superclass which clears the existing rows or drops the tables altogether. * The following is an example *setUp()* method - - public void setUp() throws Exception { - super.setUp(CLEAR_TABLES, // clears records for domain -classes - Candidate.class, Election.class, // registers Candidate and -Election as persistence-capable entity - "openjpa.Multithreaded", "true", // sets configuration property -as name-value pairs - "openjpa.Log", "SQL=TRACE"); - } +
+        
+            public void setUp() throws Exception {
+                super.setUp(CLEAR_TABLES,               // clears records for domain classes
+            	  Candidate.class, Election.class,      // registers Candidate and Election as persistence-capable entity
+            	  "openjpa.Multithreaded", "true",      // sets configuration property as name-value pairs
+            	  "openjpa.Log", "SQL=TRACE");	     
+            }
+        
+
* Notice that some configuration parameters can be set in the *setUp()* @@ -65,52 +64,55 @@ connection properties (unless your test particular database) are better be specified in *META-INF/persistence.xml*. The persistence name can be specified by overwriting the following method: - - protected String getPersistenceUnitName() { - return "test-eager-fetch"; - } - +
+        
+        protected String getPersistenceUnitName() {
+                return "test-eager-fetch";
+        }
+        
+
* *SingleEMFTestCase* ensures that *tearDown()* method deletes all rows for the domain classes involved in your test. You may want the database records to remain for analysis especially when tests are failing. In that case, you may consider suppressing the superclass behavior of *tearDown()* by simply nullifying the method as +
+        
+            public void tearDown() throws Exception {
+                 // avoids super class to delete all records
+            }
+        
+
- public void tearDown() throws Exception { - // avoids super class to delete all records - } - -{tip} - -{tip:title=Annotate O-R Mapping} +## Annotate O-R Mapping Prefer annotation over XML Descriptors for O-R Mapping because that helps to collocate relevant information. Unless, of course, the test is specific about variations in behavior across annotation and XML Descriptors. -{tip} -{tip:title=Use JUnit assert*() methods} + +## Use JUnit assert*() methods For verification, use many assertion methods provided by *JUnit* e.g. -*assertEquals()* or *assertTrue()* rather than depending on printing -trace with *System.out.println()*. If you want to trace generated SQL or -other runtime information, use appropriate *openjpa.Log* property +**assertEquals()** or **assertTrue()** rather than depending on printing +trace with **System.out.println()**. If you want to trace generated SQL or +other runtime information, use appropriate **openjpa.Log** property settings. -{tip} -{tip:title=Create JIRA Issue} + +## Create JIRA Issue Create a JIRA issue. Refer to the JIRA issue in the comments section of the new test case. -{tip} -{tip:title=ASF License} + +## ASF License Remember to include ASF License header in the comment section of all the new source or resource files. -{tip} -{tip:title=Attach the test to JIRA Issue} + +## Attach the test to JIRA Issue Package all the *.java files related to your test case in a JAR file and attach it to JIRA issue you have created. -You must check in the radio button *Grant license to ASF for inclusion in -ASF works* that appears near the bottom of *Attach File* JIRA page. -{tip} +You must check in the radio button **Grant license to ASF for inclusion in +ASF works** that appears near the bottom of **Attach File** JIRA page. +