| | | |

Junit Framework??
?IBM DW?20021201

RefactoringXP?L?????????h?ù???j????????ájava??Junit Frameworkh?java?ú??????û?Junit Framework????Junit Framework????j???h???Junit??ù?û??j??????????'?????Junit?????L?º???j??û?L??j?Junitj?h??'Junit??Y?ãõ?RefactoringXP??Y??

??i??

Junitj??j??h?????????Junitj????l???'??Junitµj????¶???j??a?????????ø????Junitµj??i?

Junit????h???

h????i????????????i?

?'?????

?ü??????

?????L?????????'?ø?????????????'õ??á

??

???h?h?h???????h?????????µj??

???L?????

h????L???û?ã?µ?

?h????L???Z???'ã

?Housekeeping???L????

???Housekeeping?????L?

??????????????h??h????L??h?????h??????hUse CaseK????h?Use CaseK??g?Use Case???g?h???K??ghh????

k??ó???h???????h???h?õh?????h?????????g??h????'??????????????????÷?????

?????K???????????????JUnitTest Infected: Programmers Love Writing Testsh?õ???j?????????????J??????????h?????K????ñ?????????Junitj??õ???

????j???????????????????gg?????ÿ?©??j???????''õ?????j?û?g

h???????ã

a??

XP???i????????g???????????????????????L??h???????¼??¶????????????g??j'õ???j???h???Junit?L'á

??????????h???????l???????µ?????????h?¶h'ý?????????'??h????ŸJ????i????gh?????g?????????»h????W?'??µ?????????i??j?????????

???????????g??ô??????????g?h??????????????????h????g??????i???????????K??????????k?????????KDefaultConnectionProxy????????OracleConnectionCacheImpl???µ?h

?h
/**
* ??I?oracle????
*
*/
public class DefaultConnectionProxy extends ConnectionProxy {

private static final String name = "Default Connection Proxy";
private static final String description =
"??I?oracle????";
private static final String author = "Ion-Global.com";
private static final int major_version = 0;
private static final int minor_version = 9;
private static final boolean pooled = true;
private ConnectionBroker connectionBroker = null;
private Properties props;
private Properties propDescriptions;
private Object initLock = new Object();
// Test Code Begin...
/*
????????????????k??
??hk????'?????????
?????OracleConnectionCacheImpl????
*/
OracleConnectionCacheImpl getConnectionCache() {
if (connectionBroker == null) {
throw new IllegalStateException("You need start the server
first.");
}

return connectionBroker.getConnectionCache();
}
// Test Code End...

???????????????????????j½??????assert?herror???assert?????õ?š
??????DefaultConnectionProxyTest??test case£

?
/**
* ?h??????
*
*/
public class DefaultConnectionProxyTest extends TestCase {
private DefaultConnectionProxy conProxy = null;
private OracleConnectionCacheImpl cacheImpl = null;
private Connection con = null;
/** ò?fixture??'
*/
protected void setUp() {
conProxy = new DefaultConnectionProxy();
conProxy.start();
cacheImpl = conProxy.getConnectionCache();
}
/** ?h?K??????
?????
*/
public void testConnectionProxyStart() {
int minConnections = 0;
int maxConnections = 0;
assertNotNull(cacheImpl);
try {
minConnections =
Integer.parseInt(PropertyManager.getProperty
("DefaultConnectionProxy.minConnections"));
maxConnections =
Integer.parseInt(PropertyManager.getProperty
("DefaultConnectionProxy.maxConnections"));
} catch (Exception e) {
// ignore the exception
}
assertEquals(cacheImpl.getMinLimit(), minConnections);
assertEquals(cacheImpl.getMaxLimit(), maxConnections);
assertEquals(cacheImpl.getCacheSize(), minConnections);
}
/** ?h?K????????????
??????????????assert?
error??assertõ??????
??i???
*/
public void testGetConnection() {
int cacheSize = cacheImpl.getCacheSize();
int activeSize = cacheImpl.getActiveSize();
int cacheSizeAfter = 0;
int activeSizeAfter = 0;
con = conProxy.getConnection();
if (con != null) {
activeSizeAfter = cacheImpl.getActiveSize();
cacheSizeAfter = cacheImpl.getCacheSize();
try {
con.close();
} catch (SQLException e) {
}
} else {
assertNotNull(con);
}
/*???'???µ?
??????µ
*/
if (cacheSize > activeSize) {
assertEquals(activeSize + 1, activeSizeAfter);
assertEquals(cacheSize, cacheSizeAfter);
} else {
assertEquals(activeSize + 1, cacheSizeAfter);
}
}
/** ?h?K??w???z??
?????????assert?error?
?assertõ??????
??i???
*/
public void testConnectionClose() {
int minConnections = cacheImpl.getMinLimit();
int cacheSize = 0;
int activeSize = 0;
int cacheSizeAfter = 0;
int activeSizeAfter = 0;
con = conProxy.getConnection();
if (con != null) {
cacheSize = cacheImpl.getCacheSize();
activeSize = cacheImpl.getActiveSize();
try {
con.close();
} catch (SQLException e) {
}
activeSizeAfter = cacheImpl.getActiveSize();
cacheSizeAfter = cacheImpl.getCacheSize();
} else {
assertNotNull(con);
}
assertEquals(activeSize, activeSizeAfter + 1);
/*??L????
?jh??????
*/
if (cacheSize > minConnections) {
assertEquals(cacheSize, cacheSizeAfter + 1);
} else {
assertEquals(cacheSize, minConnections);
}
}
/** ?Ž'??
*/
protected void tearDown() {
cacheImpl = null;
conProxy.destroy();
}
public DefaultConnectionProxyTest(String name) {
super(name);
}
/** ?????????
*/
public static void main(String args[]) {
junit.textui.TestRunner.run(DefaultConnectionProxyTest.class);
}
}

???Junit?TestSuite??????????

??

??????????g?j??i?????????????????g???ù??û???j??????g????K??û??L???????????

?1973?????????g??L??Java??jµL?OOAOOD??á

  <>

? | ? | | ? | ? | | | ? | ? | ??

Copyright® 2003 Test Engineer, Inc. All rights reserved.

 

| | | Basic Measures | Reliability and Validity | Correlation | Causality | Relationships with Qualit | References | The End | ? | ? | ? | ? | ? | ? | - | ? | - | ? | - | - | - | ArrayArrayArrayArrayPay Day Loans - Instant Approval Credit Card - Credit Card - Business Credit Card - Chase Credit CardsArrayArrayArrayArray