Tdd + Uml. It's easy with Architexa.

Who loved the TDD technique generally think that his test sufficiently documents the code.
"I do it (tests). Do you see these tests. It's easy". They said.
 Then it is not necessary to draw some UML Diagrams.

 Are you sure?

 Instead, I believe that UML diagram add value to Tdd process. I think that UML could be produced during tdd phases.
 We need a powerful tool in order to obtain that.
I think that Architexa has some interesting feature that make it the proper tool in order to join TDD and UML.
 It's more easy to start with blank diagram and step by step, test by test, to reach a final job with code and diagrams.

 I would propose you this example: (First. It enough uses drag and drop method or click something to do all. Architexa is plugin of Ecplise.)  Then, We have a Subscriber of funds which would to do an order.

 Begin with test:

@Test
public void testIstance() {
Subscriber subscriber = new Subscriber("John");
assertNotNull(subscriber);
assertEquals("John", subscriber.getName());
}
view raw gistfile1.java hosted with ❤ by GitHub

 We'll have class "Subscriber" following the TDD rules:

package com.tommyalf.blog.example.tdd.example.p1;
/**
*
*
*/
public class Subscriber {
private final String name;
public Subscriber(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
view raw gistfile1.java hosted with ❤ by GitHub

 then, We can create the first version of Layered Diagram: click on menù: Architexa/Open new Diagram editor/new layered Diagram after We can drag and drop the Subscriber class into the Diagram Window. And we can see:

                  
 After We would have an order: 

@Test
public void test_addProduct() {
Order order = new Order();
order.addProduct(new Product("My Fund"));
assertEquals(1, order.products.size());
}
view raw gistfile1.java hosted with ❤ by GitHub
 Then we have Order and Product classes: 
public class Order {
protected LinkedList<Product> products = new LinkedList<Product>();
public void addProduct(Product product) {
products.add(product);
}
public boolean complete() {
// the order is completed
return false;
}
}
view raw Order.java hosted with ❤ by GitHub
package com.tommyalf.blog.example.tdd.example.p1;
public class Product {
private final String name;
public Product(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
view raw Product.java hosted with ❤ by GitHub

 Drag and Drop these classes and We have: 
   
 By Diagram, We select all classes and Right click And choose "Open in Diagram/Class Diagram" on popup menu. After we have a diagram like:
   
 Then, now we must complete the test of Subscriber:
@Test
public void testOpenAnOrderAndAddAProduct() {
Subscriber subscriber = new Subscriber("John");
Order order = new Order();
subscriber.assignOrder(order);
Product product = new Product("radio");
subscriber.addProduct(product);
subscriber.completeOrder();
}
view raw gistfile1.java hosted with ❤ by GitHub
After we obtain this:
package com.tommyalf.blog.example.tdd.example.p1;
/**
*
*
*/
public class Subscriber {
private final String name;
private Order order;
public Subscriber(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void assignOrder(Order order) {
this.order = order;
}
public boolean completeOrder() {
return order.complete();
}
public boolean addProduct(Product product) {
order.addProduct(product);
return true;
}
}
view raw Subscriber.java hosted with ❤ by GitHub
Then, We can add some detail: 
   
 We select Order and right click and choose the item: Open in diagram / Sequence Diagram on popup menu. We can see a new Sequence Diagram. We have this sequence diagram by clicking to "2 member" and to some arrows: 
   
 We are quickly created: 2 tests, 3 classes and 3 UML diagrams. It is unbelievable.

Nessun commento: