??xml version="1.0" encoding="utf-8" standalone="yes"?>国产AⅤ无码专区亚洲AV,亚洲裸男gv网站,亚洲乱码无人区卡1卡2卡3http://m.tkk7.com/jackybu/category/2315.html<a ><b><font color=red>共有<script src=http://fastonlineusers.com/online.php?d=jackybu.blogjava.net></script>人在同时阅读此Blog</font></b></a>zh-cnWed, 28 Feb 2007 07:48:05 GMTWed, 28 Feb 2007 07:48:05 GMT60TDD(3) --转自http://m.tkk7.com/yandazhihttp://m.tkk7.com/jackybu/articles/8399.html?/dc:creator>?/author>Mon, 25 Jul 2005 04:28:00 GMThttp://m.tkk7.com/jackybu/articles/8399.htmlhttp://m.tkk7.com/jackybu/comments/8399.htmlhttp://m.tkk7.com/jackybu/articles/8399.html#Feedback0http://m.tkk7.com/jackybu/comments/commentRss/8399.htmlhttp://m.tkk7.com/jackybu/services/trackbacks/8399.html

意图~程

programming by intention

名字

Use nouns or noun phrases for class names

public class Movie {
  
//
}

public class MovieRatingComparator implements Comparator {
  
//
}

public class XMLMovieListReader implements MovieListReader {
  
//
}

Use either adjectives or generic nouns and noun phrases for interfaces

public interface Serializable {
}

public interface MovieListWriter {
  
void write(MovieList movieList) throws IOException;
}

Use verbs and verb phrases for method names


private int calculateAverageRating() {
  
int totalRating = calculateTotalRating();
  
return totalRating / ratings.size();
}


Use accepted conventions for accessors and mutators

public Category getCategory() {
  
return category;
}

public void setCategory(Category aCategory) {
  category 
= aCategory;
}

public boolean isOfCategory(Category aCategory) {
  
return category.equals(aCategory);
}

public boolean isRated() {
  
return !ratings.isEmpty();
}

public boolean hasRating() {
  
return !ratings.isEmpty();
}

public int size() {
  
return movies.size();
}


Don't put redundant information in method names

public void add(Movie movieToAdd) throws DuplicateMovieException {
  
if (this.contains(movieToAdd)) {
    
throw new DuplicateMovieException(movieToAdd.getName());
  }
  movies.add(movieToAdd);
}

There are always exceptions. Sometimes it is just clearer, and reads better, if you have type information in the method name.

public void addRating(Rating ratingToAdd) {
  ratings.add(ratingToAdd);
}

Use nouns and noun phrases for variable names.

public class Movie {
  
private String name = "";
  
private Category category = Category.UNCATEGORIZED;
  
private List ratings = null;

  
//
}


如何意图~程

包括使用隐喻Q测试优先,重构Q作出假定,让编译器告诉你下一步做什?q几U技巧?BR>
公用词汇?帮助你理解这个领域?BR>                      帮助你取名字?BR>

"NO COMMENT"

Incomplete code

// TODO: The tree should be balanced after doing the insertion.
// CODE DEBT: the looping structure is a bit convoluted, could use
// some method extraction.


Refactoring doesn't make it clear enough

// NEEDS WORK: I tried extract method, but it's still awkward.
// Maybe refactoring to a Strategy would clean it up?


Use of an unusual algorithm

// I used an AVL Tree algorithm here to keep the tree balanced.


Use of a published algorithm

// This AVL alorithm was based on Brad Appleton's implementation at
// http://www.enteract.com/~bradapp/ftp/src/libs/C++/AvlTrees.html


Performance tuning

// A circular queue is used here for performance reasons: to avoid
// having to move elements around.


Class comment

/**
 * This class represents a single movie title. It is responsible for
 * maintaining its own ratings, reviews, etc.
 */



]]>
TDD(1)--转自http://m.tkk7.com/yandazhihttp://m.tkk7.com/jackybu/articles/8397.html?/dc:creator>?/author>Mon, 25 Jul 2005 04:26:00 GMThttp://m.tkk7.com/jackybu/articles/8397.htmlhttp://m.tkk7.com/jackybu/comments/8397.htmlhttp://m.tkk7.com/jackybu/articles/8397.html#Feedback0http://m.tkk7.com/jackybu/comments/commentRss/8397.htmlhttp://m.tkk7.com/jackybu/services/trackbacks/8397.htmlTDD是这样一U设计风?/FONT>

Maintain an exhaustive suite of Programmer Tests

l护一套程序员试的框?/P>

No code goes into production unless it has associated tests

除非它已l合试Q品不写入M代码

Write the tests first

先写试

Tests determine what code you need to write

试军_你需要写什么代?/P>

public void testEmptyList() {
    MovieList emptyList 
=newMovieList();
    assertEquals(
"Empty list should have size of 0"0, emptyList.size());
}



要通过上面的测试,你必dZ个类MovieListQ和一个方法size();

Qeclipse?FONT size=2>快速修复功能能帮你搞定哦。看来先写测试还是很方便?^^*Q?BR>

让计机来告诉你

你需要增加类或者方法,~译器会告诉你。(eclipse会向你抱怨有cannot be resolved 的)

下面看看代码的演q?BR>
public void testRating() {
  assertEquals(
"Bad average rating.",4,starWars.getAverageRating());
}



public void testRating() {
  starWars.addRating(
3);
  starWars.addRating(
5);
  assertEquals(
"Bad average rating.",4,starWars.getAverageRating());
}


public void testRating() {
  Movie starWars 
= new Movie("Star Wars");
  starWars.addRating(
3);
  starWars.addRating(
5);
  assertEquals(
"Bad average rating.",4,starWars.getAverageRating());
}



非常有意思,和我们^时写代码的顺序相?BR>
下面看看getAverageRating()Q?BR>
public int getAverageRating() {
  
return 4;
}


public int getAverageRating() {
  
return (3 + 5/ 2;
}



private int totalRating = 0;


public void addRating(int newRating) {
  totalRating 
+= newRating;
}




public int getAverageRating() {
  
return totalRating / 2;
}



private int numberOfRatings = 0;

public void addRating(int newRating) {
  totalRating 
+= newRating;
  numberOfRatings
++;
}


public int getAverageRating() {
  
return totalRating / numberOfRatings;
}



实际上,每次变化之后都重新编译和q行q个试?BR>

Agile Modeling and TDD


采用XPQ极限编E)的项目都采用了TDD的辅助手Dc徏模(modelingQ是XP当中很重要的的一个部分。XP开发者用用户叙qͼuser storiesQ?,用户叙述是清晰的敏捷模型?BR>
创徏敏捷模型能够帮助我们TDD工作Q这是因为,他能揭示我们需要的试。一个敏h型草囄背后L隐含着q样的思考“我怎样来测试他”,q将D一个新的测试案例?BR>



]]>
TDD(2) --转自http://m.tkk7.com/yandazhihttp://m.tkk7.com/jackybu/articles/8398.html?/dc:creator>?/author>Mon, 25 Jul 2005 04:26:00 GMThttp://m.tkk7.com/jackybu/articles/8398.htmlhttp://m.tkk7.com/jackybu/comments/8398.htmlhttp://m.tkk7.com/jackybu/articles/8398.html#Feedback0http://m.tkk7.com/jackybu/comments/commentRss/8398.htmlhttp://m.tkk7.com/jackybu/services/trackbacks/8398.html阅读全文

]]>
TDD faqhttp://m.tkk7.com/jackybu/articles/8396.html?/dc:creator>?/author>Mon, 25 Jul 2005 04:23:00 GMThttp://m.tkk7.com/jackybu/articles/8396.htmlhttp://m.tkk7.com/jackybu/comments/8396.htmlhttp://m.tkk7.com/jackybu/articles/8396.html#Feedback0http://m.tkk7.com/jackybu/comments/commentRss/8396.htmlhttp://m.tkk7.com/jackybu/services/trackbacks/8396.html在TDD中煎熬了已有一阵子?所谓吃得苦中苦,方ؓZ?回首q段旅程,需要ȝ的东西很?我只理理曄出现在脑中的疑?q提供本人的对该问题的理?以后随时补充.

☆写试的时间比写代码的旉q多?

在有些情况下的确如此,但是不要太担?Z么呢? Ҏ我的体会:

1.有了试,你会写很多本来不需?初看h应该是有?的代?/P>

2.写测试的q程是在解决问题的q程,因此你会比较Ҏ,早地明白你到底应该做什?q样在写代码?p节省旉

3.寚w构帮助很?有了试,你才能放心大胆的q行重构.

4.长远来看,因ؓTDD会促q你写出好的代码,q且你会l常的重?因此会降低维护代?/P>

☆需要ؓ每个Ҏ~写试?

当然不需?我们所写的试必须是针Ҏ口方法的.一般认为处理业务逻辑的方?以及领域模型对象的关键行为是必须q行试. 其它的一些方法需要自己把?当然q需要经?

我现在只是一个新?没有啥经?我判断某个方法是否需要测?依据有两?

1.是否满我上面列出的必须试条g

2.是否值的试,q一条主要是心理因素,例如Ҏ个方法感觉心里没?那就先编写测?

☆TDD是一U测试新技术吗?

当然不是,TDDҎ׃是一Ҏ试技?它是一U新的开发方?只是借助试而已.

☆项目一开始没有采用TDD,在项目中期再引入TDD,可行?

一般来说不推荐在项目中期再引入TDD,q是׃TDD内在Ҏ决定的.

1.TDD是一U新的开发方?在开发过E中需要你转变思想,需要在实践不断完善自己,而且它本w就h一个较陡学习的坡度,q一点在很多文章中都提到q?因此在项目中期引入TDD,会立x廉目进?寚w目本w帮助也不会太大.

2.TDD在你开始写试?会驱动你寚w题进行思?然后持箋q行功能增强和重?在项目中?如果你编写一个测?q时你需要项目早期的一个组?但是q个lgq没有满你的测?因ؓҎ没有测?.现在因ؓ该组件有问题,试通不q?如果q时你再lg~写单元试,失M试驱动开发的优势?此时TDD的效果就大打折扣?

当然,在没有项目压力的情况?引入TDD是没有Q何问题的.不过我还是推荐在目开始就引入TDD是最佳选择.

☆ؓ也存在的lg补充单元试值得?

在上一问题的第二点原因中已l提到过,感觉不值得.在这U情况下,用一般的Ҏ试一下即?比如java的main()Ҏ.

☆TDD~写的测试案例是比较复杂的吗?

在TDD?试是一步一步演化的,需要你一直保持简单设计的理念,因此,一般测试案例是比较清晰?如果发现你的试非常复杂,应该是你没有抓住问题的重Ҏ者没有掌握正?有效的方?



]]>
Test-Driven Developmenthttp://m.tkk7.com/jackybu/articles/8395.html?/dc:creator>?/author>Mon, 25 Jul 2005 04:22:00 GMThttp://m.tkk7.com/jackybu/articles/8395.htmlhttp://m.tkk7.com/jackybu/comments/8395.htmlhttp://m.tkk7.com/jackybu/articles/8395.html#Feedback0http://m.tkk7.com/jackybu/comments/commentRss/8395.htmlhttp://m.tkk7.com/jackybu/services/trackbacks/8395.html

 

Test-Driven Development

http://www.xprogramming.com/xpmag/whatisxp.htm#test

Extreme Programming is obsessed with feedback, and in software development, good feedback requires good testing. Top XP teams practice "test-driven development", working in very short cycles of adding a test, then making it work. Almost effortlessly, teams produce code with nearly 100 percent test coverage, which is a great step forward in most shops. (If your programmers are already doing even more sophisticated testing, more power to you. Keep it up, it can only help!)

It isn't enough to write tests: you have to run them. Here, too, Extreme Programming is extreme. These "programmer tests", or "unit tests" are all collected together, and every time any programmer releases any code to the repository (and pairs typically release twice a day or more), every single one of the programmer tests must run correctly. One hundred percent, all the time! This means that programmers get immediate feedback on how they're doing. Additionally, these tests provide invaluable support as the software design is improved.

在上面的图中Q列出的的是XP?2个团队实cTest-Driven Development是其中之一?/DIV>
Kent Beck 的著作TDD(Test Driven Development) 中详l讲qC试驱动开发?/DIV>
在XP中测试是一U设计,不是单的Z试你的功能是否实现。测试先行一个目?/DIV>
是可以在代码~写之前Q保证测试已l写好;其实q些试的另一个目的就是设计接口,
保证接口在以后的修改q程中能够满x试(设计Q?EM>当你有意或无意修Ҏ口的时候,你必d?/FONT>
修改试 要改动接口的时候,也应该是先修Ҏ试,再修改代码。而不是修改代码等着报错再修?/FONT>
试(设计Q?/FONT>。(试必须100%通过才能q行下一个功能)Q这h试也是在提醒你,接口已经改变?/FONT>
实际上,设计已经改变。当你修改单元测试的时候,可能׃遭到抱怨。ؓ什么?你修改了设计
Q别人的代码是依赖你修改前的试Q设计)Q那么新的测试(设计Q中的变动可能要影响?/DIV>
别h已有的代码?/DIV>
 
当你使用TDD的时候一定要说明是测试驱动开发还是测试驱动设计。这两者是有区别的。测试驱?/DIV>
开发,是通过试定义所要开发的功能的接口,然后实现功能的开发过E。对于测试驱动设计,在XP中似?/DIV>
已经消失了,而是被测试驱动开发所取代。另外在XP中有用于描述设计的,SimpleDesign QDesign Improvement.
在XP中测试是一U设计,设计之后才有开发,q也是Z么要试先行了?/DIV>
在XP中测试是一U文,用于描述设计?/DIV>


]]> վ֩ģ壺 ޾Ʒa߹ۿ| ˾Ʒһ| AvרDVD| ëƬվ߹ۿ| þerƷѹۿ8| avƬ߹ۿ| xxxձ18| þþþƷ| ƷѾƷ| va˳Ƶվȫ| Ƶѹۿ| Ļ| avƬ߹ۿ| ƷѾþþþùһ| þþþþ޾Ʒ| ˾þô߽| ۺƵ߹ۿ| ޾ɫ߲| ۺAVһҳ| һɫþ88ۺ| ձƬ߿a| ëƬa߹ۿ67194| 69Ƶ߹ۿ| ٸ͵˾ƷƵ| Ӱ߹ۿѸ| һѵӰ| ҹɫ˽ӰԺվ| ŮƵӴȫƵѵ| ޱר| ͬgayƬ| avպavӰ| þþƷav18| ޸Ʒһ | 97޾ƷȫƵ | Ļ޹˾þþƷ| Ʒһ| Ʒѿ㽶| ѾƷԲĹۿ| ޹ۺ | ޵һӰԺ| רAVվ |