2004 12
... 3... 3... 4... 5... 6... 6 JUnit... 6... 7 Apache Cactus... 7 HttpUnit/ServletUnit... 8 utplsql... 8 Clover... 8 Anthill Pro... 9... 10... 10... 10 SQL... 10 Java... 11... 11... 12... 12 setter getter... 12 CRUD... 12... 12... 13... 13... 13... 14 : StringUtils... 14 : Person... 16 : StringUtilsTester... 18 : PersonTester... 20... 21... 22 ADF... 23 ADF... 23 ADF CRUD... 25 2 Oracle Corporation Getting Started With Unit-testing
Java 1 1 3 Oracle Corporation Getting Started With Unit-testing
3 substitute() public static void testsubstitute() assertequals("a bear", StringUtils.substitute("a goose", "goose", "bear")); substitute() public static String substitute (String text, String replace, String with) return new String("a donkey"); a bear a donkey 1 public static String substitute (String text, String replace, String with) return new String("a bear"); substitute() substitute() text replace with NULL 4 Oracle Corporation Getting Started With Unit-testing
IDE 3 1 2 3 assertequals() substitute ("a goose", "goose", "bear") a bear 5 Oracle Corporation Getting Started With Unit-testing
2 1 1 1 JUnit Java JUnit OTN JUnit Extension JDeveloper JUnit JUnit 6 Oracle Corporation Getting Started With Unit-testing
[JDeveloper home]\jdev\lib\ext Oracle JDeveloper 10.1.2 http://www.junit.org JUnit JVM Java JUnit JDeveloper JUnit HTTP EJB JVM http://www.mockobjects.com Apache Cactus Apache Cactus Cactus JUnit OC4J Tomcat Cactus EJB JSP XSLT Cactus http://jakarta.apache.org/cactus/ 7 Oracle Corporation Getting Started With Unit-testing
Cactus Web Cactus HttpUnit HttpUnit/ServletUnit HttpUnit Web HTTP HttpUnit JavaScript Cookie Web HttpUnit ServletUnit JUnit Cactus HttpUnit ServletUnit http://httpunit.sourceforge.net/ HttpUnit UI HttpUnit utplsql Oracle PL/SQL PL/SQL http://utplsql.sourceforge.net/ utplsql Clover 1 Clover Jakarta Ant Clover Clover Clover JDeveloper 10g Clover http://www.thecortex.net/clover/ Clover 8 Oracle Corporation Getting Started With Unit-testing
Clover レポートの例 JDeveloper に統合できる Clover Anthill Pro Anthill Pro は ソフトウェア ビルド管理サーバーです Anthill Pro により Apache Ant のようなビルダー フレームワークに基づくビルド プロセス ユニット ユニット テストの概要 9 Oracle Corporation 発行 Getting Started With Unit-testing の翻訳版です
Clover CVS Anthill Pro http://www.urbancode.com/products/anthillpro Anthill JUnit JUnit.org (http://www.junit.org) Extensions JSP 1 SQL Java SQL SQL 2 SQL Java 10 Oracle Corporation Getting Started With Unit-testing
SQL Java Java 2 TopLink 1 TopLink TopLink SQL TopLink CHECK Java PL/SQL SQL 2 Java - IDE Java 2 PL/SQL Developer Toad 1 11 Oracle Corporation Getting Started With Unit-testing
2 1 jar setter getter Java Bean getter setter getter setter getter setter getter setter CRUD TopLink setter getter - 1 2 CRUD private protected 12 Oracle Corporation Getting Started With Unit-testing
JUnit JUnit http://www.junit.org JUnit Javadoc FAQ Wiki http://c2.com/cgi/wiki?unittest ADF ADF Toy Store Demo http://www.oracle.com/technology/products /jdev/collateral/papers/10g/adftoy store.html 13 Oracle Corporation Getting Started With Unit-testing
: StringUtils substitute() bear true isabear() NULL trimemptytonull() package oracle.code.utils; import java.util.list; import java.util.arraylist; import java.util.stringtokenizer; public class StringUtils private static String BEAR = new String("bear"); private static String EMPTY = new String(""); * * * * in.replaceall(find,newstring) * * @param in: * @param find: * @param newstring: * @return in * newstring public static String substitute (String in, String find, String newstring) // NULL if ( in == null find == null newstring == null) return in; char[] working = in.tochararray(); StringBuffer stringbuffer = new StringBuffer(); // find int startindex = in.indexof(find); if (startindex < 0) return in; int currindex=0; while (startindex > -1) for(int i = currindex; i < startindex; i++) stringbuffer.append(working[i]); 14 Oracle Corporation Getting Started With Unit-testing
currindex = startindex; stringbuffer.append(newstring); currindex += find.length(); startindex = in.indexof(find,currindex); for (int i = currindex; i < working.length; i++) stringbuffer.append(working[i]); return stringbuffer.tostring(); * s "bear" true * * @param s: * @return s "bear" true public static boolean isabear(string s) return BEAR.equals(s); * ""NULL * * @param string: * @return NULL string public static String trimemptytonull (String string) if (string == null EMPTY.equals(string.trim())) return null; return string; 15 Oracle Corporation Getting Started With Unit-testing
: Person Person equal getter setter package oracle.code.model; public class Person private String name; private Integer age; public Person () * * * @param name: * @param age: public Person (String name, Integer age) this.name = name; this.age = age; * * * @param name: public void setname(string name) this.name = name; * * * @return public String getname() return this.name; * * * @param age: public void setage(integer age) this.age = age; * * * @return 16 Oracle Corporation Getting Started With Unit-testing
public Integer getage() return this.age; * * * @param p: * @return this p true public boolean equals(object p) // p this true if (this == p) return true; // p false if (!(p instanceof Person)) return false; // true Person q = (Person)p; return ( (this.name == null? q.name == null: this.name.equals(q.name)) && (this.age == null? q.age == null: this.age.equals(q.age)) ); 17 Oracle Corporation Getting Started With Unit-testing
: StringUtilsTester StringUtils testsubstitute() JDeveloper JUnit New General Unit Tests (JUnit) Test Case Subject Class StringUtilsTester Package Name oracle.code.utils.test Extends junit.framework.testcase package oracle.code.utils.test; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; import oracle.code.utils.stringutils; import oracle.code.model.person; public class StringUtilsTester extends TestCase public StringUtilsTester(String stestname) super (stestname); * String substitute (String, String, String) public void testsubstitute() // A: assertequals("a bear", StringUtils.substitute("a goose", "goose", "bear")); // B: assertequals("a goat", StringUtils.substitute("a goose", "goose", "bear")); // C: // assertequals("substitute goose by bear", "a goat", StringUtils.substitute("a goose", "goose", "bear")); 18 Oracle Corporation Getting Started With Unit-testing
// D: asserttrue/false assertequals("a bear is a bear", true, StringUtils.isABear("bear")); asserttrue("a bear is a bear", StringUtils.isABear("bear")); assertfalse("a goat is not a bear", StringUtils.isABear("goat")); * String trimemptytonull(string) public void testtrimemptytonull() // E: assertnull/assertnotnull assertequals("trim empty string to null is null", null, StringUtils.trimEmptyToNull("")); assertnull("trim empty string to null is null", StringUtils.trimEmptyToNull("")); // trimemptytonull assertnotnull("trim x to null is not null", StringUtils.trimEmptyToNull("x")); 19 Oracle Corporation Getting Started With Unit-testing
: PersonTester Person JUnit JDeveloper JUnit package oracle.code.model.test; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; import oracle.code.model.person; public class PersonTester extends TestCase public PersonTester(String stestname) super(stestname); * boolean equals (Person) public void testequals() // Person jan = new Person("Jan", new Integer(10)); Person piet = new Person("Jan", new Integer(10)); Person joris = new Person("Jan", new Integer(10)); Person fred = new Person(); Person klaas = new Person("Klaas", new Integer(10)); // F: assertequals // assertequals("jan must equal itself", jan, jan); // assertequals("jan equals piet", jan, piet); assertequals("so piet must equal jan", piet, jan); // assertequals("piet equals joris", piet, joris); assertequals("so jan must equal joris", jan, joris); // assertequals("fred equals itself", fred, fred); assertfalse("fred not equals null", fred.equals(null)); assertfalse("jan must not equal klaas", jan.equals(klaas)); // G: assertsame assertsame("fred is same object as fred, fred, fred); assertnotsame("jan is not same as piet", jan, piet); 20 Oracle Corporation Getting Started With Unit-testing
PersonTester StringUtilsTester JUnit 1 JDeveloper JUnit New General Unit Tests (JUnit) Test Suite Class AllTests oracle.code.test Extends java.lang.object Cases Add Suite() JUnit test addtest()addtestsuite() suite() package oracle.code.test; import junit.framework.test; import junit.framework.testsuite; public class AllTests public static Test suite() TestSuite suite = new TestSuite("AllTests"); suite.addtestsuite(oracle.code.model.test.persontester.class); suite.addtestsuite(oracle.code.utils.test.stringutilstester.class); return suite; public static void main (String args[]) String args2 [] = "-noloading", "oracle.code.test.alltests"; junit.swingui.testrunner.main(args2); 21 Oracle Corporation Getting Started With Unit-testing
PersonTester SetUp()tearDown() 2 JUnit test setup() teardown() 1 package oracle.code.model.test; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; import oracle.code.model.person; public class PersonTester extends TestCase private Person jan; private Person piet; private Person joris; private Person fred; private Person klaas; public PersonTester(String stestname) super(stestname); public void setup() this.jan = new Person("Jan", new Integer(10)); this.piet = new Person("Jan", new Integer(10)); this.joris = new Person("Jan", new Integer(10)); this.fred = new Person () ; this.klaas = new Person("Klaas", new Integer(10)); public void teardown() this.jan = null; this.piet = null; this.joris = null; this.fred = null; this.klaas = null; * boolean equals (Person) public void testequals() // F: assertequals // assertequals("jan must equal itself", jan, jan); // assertequals("jan equals piet", jan, piet); assertequals("so piet must equal jan", piet, jan); 22 Oracle Corporation Getting Started With Unit-testing
// assertequals("piet equals joris", piet, joris); assertequals("so jan must equal joris", jan, joris); // assertequals("fred equals itself", fred, fred); assertfalse("fred not equals null", fred.equals(null)); assertfalse("jan must not equal klaas", jan.equals(klaas)); // G: assertsame assertsame("fred is same object as fred", fred, fred); assertnotsame("jan is not same object as piet", jan, piet); ADF ADF ADF HR HR HR ADF JDeveloper JUnit New General Unit Tests (JUnit) Business Components Test Fixture JDBC DataSource JDeveloper J2EE Web/EJB Bundled Exception Mode true 23 Oracle Corporation Getting Started With Unit-testing
package oracle.hr.testfixtures; import oracle.jbo.*; import oracle.jbo.client*; public class HrServicesConnectFixture private static final String AM = "oracle.hr.services.hrservices"; private static final String CF = "HrServicesLocal"; private ApplicationModule applicationmodule; public HrServicesConnectFixture() * public void setup() throws Exception this.applicationmodule = Configuration.createRootApplicationModule(AM, CF); /* * ADF/Struts Bundled Exception Mode this.applicationmodule.gettransaction().setbundledexceptionmode( true ); * public void teardown() throws Exception Configuration.releaseRootApplicationModule(this.applicationModule, true); * * * @return public ApplicationModule getapplicationmodule() return this.applicationmodule; 24 Oracle Corporation Getting Started With Unit-testing
ADF CRUD ADF 1 ManagerId DepartmentId ID package oracle.hr.dataaccess; import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; import oracle.hr.testfixtures.hrservicesconnectfixture; import oracle.jbo.jboexception; import oracle.jbo.key; import oracle.jbo.viewobject; import oracle.jbo.row; public class DepartmentsTests extends TestCase private static String DEPARTMENTID = "DepartmentId"; private static String DEPARTMENTNAME = "DepartmentName"; private static String MANAGERID = "ManagerId"; private static String LOCATIONID = "LocationId"; HrServicesConnectFixture connectionfixture = new HrServicesConnectFixture(); public DepartmentsTests (String stestname) super(stestname); public void testdepartmentsviewobjectlifecycle() ViewObject departmentsview = this.connectionfixture.getapplicationmodule().findviewobject( "Depart ments"); * NULL assertnotnull(departmentsview); * Row departmentrow = departmentsview.createrow(); try 25 Oracle Corporation Getting Started With Unit-testing
departmentrow.setattribute(this.departmentid, "1"); departmentrow.setattribute(this.departmentname, "test department"); departmentrow.setattribute(this.managerid, "100"); departmentrow.setattribute(this.locationid, "1000"); catch (JboException jbo) fail("should not have thrown this " + jbo.getclass().getname() + " exception yet due to bundled exception mode"); this.connectionfixture.getapplicationmodule().gettransaction(). commit(); * Row[] departmentrows = new Row[0]; try Key key = departmentrow.getkey(); departmentrows = departmentsview.findbykey(key, 1); assertequals("expect to find one department with id 1", departmentrows.length, 1) ; catch (JboException jbo) fail("should not have thrown this " + jbo.getclass().getname() + " exception yet due to bundled exception mode"); * try departmentrows[0].setattribute(this.departmentname, "testing department"); this.connectionfixture.getapplicationmodule().gettransaction(). commit(); catch (JboException jbo) fail("should not have thrown this " + jbo.getclass().getname() + " exception yet due to bundled exception mode"); * try 26 Oracle Corporation Getting Started With Unit-testing
departmentrows[0].remove(); this.connectionfixture.getapplicationmodule().gettransaction(). commit(); catch (JboException jbo) fail("should not have thrown this " + jbo.getclass().getname() + " exception yet due to bundled exception mode"); public void setup() throws Exception this.connectionfixture.setup(); public void teardown() throws Exception this.connectionfixture.teardown(); 27 Oracle Corporation Getting Started With Unit-testing
2004 12 : Jan Kettenis, Remco de Blok Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065 U.S.A. : : +1.650.506.7000 : +1.650.506.7200 www.oracle.com Copyright 2004, Oracle. All rights reserved. Oracle Oracle Corporation