mai putin stres. mai multa calitate.files.meetup.com/1531159/intro_automatizarea_testelor.pdfsyneto...

42
Mai putin stres. Mai multa calitate.

Upload: others

Post on 04-Oct-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Mai putin stres. Mai multa calitate.

Page 2: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Syneto

Agile Coach

Product Owner

Developer din 2000 Interesat de agile din 2008 Membru al #agileworks Timisoara din 2009

Page 3: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 4: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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.

Page 5: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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?

Page 6: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Nu mentinem ritmul

Creste timpul de release

(Mai probabil) Testam mai putin

Scade calitatea

Page 7: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Concepem si automatizam testele de verificare si validare a softului construit

Lasam calculatorulsa verificesi sa validezepentru noi

Page 8: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Scop Refactoring Tipuri de teste Unelte Unit testing TDD Concluzii

Page 9: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 10: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 11: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 12: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 13: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Scapam de “spaghetti code”

Schimbam design existent Facem codul mai usor de

inteles si mentinut Gasim bug-uri Programam mai usor ulterior

Page 14: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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);

}

Page 15: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Exemplu de refactoring

Comments are code smells

Jason Gorman - Codemanship

http://www.youtube.com/watch?v=3cNR0PohDPM

Page 16: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 17: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 18: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 19: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

SUnit jUnit DbUnit NUnit PHPUnit PyUnit Test::Unit

rSpec jBehave

Page 20: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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);

}

} }

Page 21: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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);

} }

Page 22: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

require 'watir-webdriver'

b = Watir::Browser.new(:ie)b.goto 'http://www.openagile.ro'puts b.titleb.close

Page 23: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Record Replay C#, Java, Perl, PHP,

Python, Ruby Fragil Nevoie de

refactoring

Page 24: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

|eg.Division||numerator|denominator|quotient?||10 |2 |5 ||12.6 |3 |4.2 ||100 |4 |33 |

Page 25: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 26: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

SUnit 1997 – jUnit 2000 – mock objects Restul e istorie

Page 27: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

<?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

Page 28: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 29: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 30: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Trebuie mentinute Refactoring Design

Decuplare

Coeziune

Sunt mai dificil de adaugat pe cod existent

Working Effectively with Legacy Code

Page 31: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 32: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 33: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 34: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Emergenta Doar cat e

necesar

Page 35: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 36: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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

Page 37: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Interfata in Java pentru Tokyo Tyrant

Kent Beck (autor prima carte TDD)

http://www.vimeo.com/10789674 http://www.vimeo.com/10927341

Page 38: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru
Page 39: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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.

Page 40: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

www.xunitpatterns.com googletesting.blogspot.com www.martinfowler.com www.exampler.com www.youtube.com/user/parlezuml dannorth.net www.infoq.com lisacrispin.com

Page 41: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

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)

Page 42: Mai putin stres. Mai multa calitate.files.meetup.com/1531159/Intro_automatizarea_testelor.pdfSyneto Agile Coach Product Owner Developer din 2000 Interesat de agile din 2008 Membru

Email: [email protected]: @FlaviusStef

Web: flaviusstef.posterous.com