mai putin stres. mai multa calitate.files.meetup.com/1531159/intro_automatizarea_testelor.pdfsyneto...
TRANSCRIPT
Mai putin stres. Mai multa calitate.
Syneto
Agile Coach
Product Owner
Developer din 2000 Interesat de agile din 2008 Membru al #agileworks Timisoara din 2009
Nu mai avem timp sa il testam!Faceti release odata!!!!!
Trebuie sa il terminam pana saptamanaviitoare. Vino, te rog, si in weekend…
De doua zile ma chinui sa gasesc un bug si nu reusesc sa ii dau de cap
http://agilemanifesto.org Principii
Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage.
Cum putem sa:
Acceptam cerinte noi,
Mentinem ritmul…
… cand cantitatea de cod pe care trebuie sa o testam (manual) creste liniar cu numarul de functionalitati noi pe care le adaugam?
Nu mentinem ritmul
Creste timpul de release
(Mai probabil) Testam mai putin
Scade calitatea
Concepem si automatizam testele de verificare si validare a softului construit
Lasam calculatorulsa verificesi sa validezepentru noi
Scop Refactoring Tipuri de teste Unelte Unit testing TDD Concluzii
Specificatii Inainte de dezvoltare
Documentatie Mereu actualizata
Plasa de siguranta Cand schimbam
Localizarea defectelor Cand apar bug-uri
Imbunatatirea calitatii Codul testabil este mai decuplat
Scaderea riscului Construim ce trebuie Nu stricam ce exista
To restructure software by applying a series of refactorings, without changing its observable behavior.
Martin Fowler
• Tehnica esentiala in agile• Schimbam designul codului existent• Nu adaugam de cod nou
Scapam de “spaghetti code”
Schimbam design existent Facem codul mai usor de
inteles si mentinut Gasim bug-uri Programam mai usor ulterior
void printOwing() {printBanner(); //print details System.out.println ("name: " + _name); System.out.println ("amount " + getOutstanding());
}
void printOwing() {printBanner();printDetails(getOutstanding());
}
void printDetails (double outstanding) { System.out.println ("name: " + _name); System.out.println ("amount " + outstanding);
}
Exemplu de refactoring
Comments are code smells
Jason Gorman - Codemanship
http://www.youtube.com/watch?v=3cNR0PohDPM
SUnit jUnit DbUnit NUnit PHPUnit PyUnit Test::Unit
rSpec jBehave
namespace bank {
using NUnit.Framework;
[TestFixture]
public class AccountTest {
[Test]
public void TransferFunds() {
Account source = new Account();
source.Deposit(200.00F);
Account destination = new Account();
destination.Deposit(150.00F);
source.TransferFunds(destination, 100.00F);
Assert.AreEqual(250.00F, destination.Balance);
Assert.AreEqual(100.00F, source.Balance);
}
} }
public class SampleTest extends DBTestCase {
[…]
// Implements required setup methods here ...
public void testMe() throws Exception {
// Execute the tested code that modifies the database here ...
[…]
// Fetch database data after executing your code
IDataSet databaseDataSet = getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("TABLE_NAME");
// Load expected data from an XML dataset
IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(
new File("expectedDataSet.xml"));
ITable expectedTable = expectedDataSet.getTable("TABLE_NAME");
// Assert actual database table match expected table
Assertion.assertEquals(expectedTable, actualTable);
} }
require 'watir-webdriver'
b = Watir::Browser.new(:ie)b.goto 'http://www.openagile.ro'puts b.titleb.close
Record Replay C#, Java, Perl, PHP,
Python, Ruby Fragil Nevoie de
refactoring
|eg.Division||numerator|denominator|quotient?||10 |2 |5 ||12.6 |3 |4.2 ||100 |4 |33 |
SUnit 1997 – jUnit 2000 – mock objects Restul e istorie
<?phprequire_once 'PHPUnit/Framework.php';
class ArrayTest extends PHPUnit_Framework_TestCase{
protected $fixture;
protected function setUp(){
// Create the Array fixture.$this->fixture = array();
}
public function testNewArrayIsEmpty(){
// Assert that the size of the Array fixture is 0.$this->assertEquals(0, sizeof($this->fixture));
}
public function testArrayContainsAnElement(){
// Add an element to the Array fixture.$this->fixture[] = 'Element';
// Assert that the size of the Array fixture is 1.$this->assertEquals(1, sizeof($this->fixture));
}}?>
• Teste• Setup/Teardown• Suite• Test runner• 4 faze
• Set up• Exercita• Verifica• Tear down
Terminologie
SUT
DOC
Intre obiecte exista dependinte Altele nu pot fi folosite (sist. remote, ceas) Cum testam in mod individual?
Inlocuim DOC cu “dubluri”
Stubs, Mocks, Dummies, Spies, Fake objects
require 'test/unit‘require 'mocha‘
class MiscExampleTest < Test::Unit::TestCase
def test_mocking_a_class_method
product = Product.new
Product.expects(:find).with(1).returns(product)
assert_equal product, Product.find(1)
end
def test_mocking_an_instance_method_on_a_real_object
product = Product.new
product.expects(:save).returns(true)
assert product.save
endend
Trebuie mentinute Refactoring Design
Decuplare
Coeziune
Sunt mai dificil de adaugat pe cod existent
Working Effectively with Legacy Code
Metoda de dezvoltare in 3 pasi
Scrii un test care esueaza
Scrii codul care il face sa treaca
Refactor (cod + test) Pasi mici Variaza dimensiunea pasului
Feedback rapid legat de deciziile de design Scapam de “analysis paralysis” Codul devine testabil Codul testabil e mai decuplat Codul decuplat e usor de intretinut
Emergenta Doar cat e
necesar
Does TDD scale to extremely large systems? What new tests would you have to write? What new kinds of refactorings would you need?
The largest, totally test-driven system I've been involved with is at LifeWare (www.lifeware.ch). After 4 years and 40 person/years, the system contains approximately 250,000 lines of functional code and 250,000 lines of test code in Smalltalk. There are 4,000 tests, executing in under 20 minutes. The full suite is run several times each day. The amount of functionality in the system seems to have no bearing on the effectiveness of TDD. By eliminating duplication, you tend to create more smaller objects, and those objects can be tested in isolation independent of the size of the application.
Kent Beck, TDD: By Example
Programarea e dificila Limbaj Mediu (OS, editor, librarii) OOD Patterns Testare
Avem nevoie de “mesteri” (craftsmen) Invata continuu Exerseaza (craftsmanship movement) Code retreats, pair programming, dojos
Interfata in Java pentru Tokyo Tyrant
Kent Beck (autor prima carte TDD)
http://www.vimeo.com/10789674 http://www.vimeo.com/10927341
Automatizeaza-ti testele pentru a crestecalitatea codului si a o mentine.
Foloseste refactoring des pentruimbunatarirea designului.
Foloseste TDD pentru a-ti “conduce” designul.
Testele nu inlocuiesc codul de calitate. Alege un proiect nou la care sa aplici aceste
practici. Nu trebuie sa fie unul de la lucru.
www.xunitpatterns.com googletesting.blogspot.com www.martinfowler.com www.exampler.com www.youtube.com/user/parlezuml dannorth.net www.infoq.com lisacrispin.com
Test-Driven Development: by Example (Kent Beck) Refactoring (Martin Fowler) xUnit Test Patterns (Gerrard Meszaros) Growing OO software guided by tests (Steve
Freeman, Nat Pryce) Agile Testing (Lisa Crispin, Janet Gregory)
Email: [email protected]: @FlaviusStef
Web: flaviusstef.posterous.com