Laste ned presentasjonen
Presentasjon lastes. Vennligst vent
PublisertKamilla Henriksen Endret for 9 år siden
1
Hvordan uttrykke krav som tester Og omvendt Johannes Brodwall
2
FitNesse eksempel #1
4
© Steria | 29/06/2014Presentation titlep4 © Steria Agenda (skjult) Vekker: Hvorfor oppfører folk seg rart under fullmåne? Appertiff: Eksempel – test av signering V-modellen: Krav og testing Fra V til I Kostnaden av overleveringer Utviklers tester skaper design Utviklers tester uttrykkes som krav En testers mindset
5
© Steria | 29/06/2014Presentation titlep5 © Steria
6
| 29/06/2014Presentation titlep6 © Steria Krav Akseptanse Design Enhetstest Kode
7
© Steria | 29/06/2014Presentation titlep7 © Steria Krav Akseptanse Design Enhetstest Kode
8
© Steria | 29/06/2014Presentation titlep8 © Steria Krav Akseptanse
9
Hva er krav?
10
© Steria | 29/06/2014Presentation titlep10 © Steria ”Hvorfor skal kunden ha noe løst?”
11
© Steria | 29/06/2014Presentation titlep11 © Steria Behovsforståelse
12
© Steria | 29/06/2014Presentation titlep12 © Steria ”Hva skal løse når?”
13
© Steria | 29/06/2014Presentation titlep13 © Steria Planlegging
14
© Steria | 29/06/2014Presentation titlep14 © Steria ”Hvordan skal systemet løse hver enkelt krav?”
15
© Steria | 29/06/2014Presentation titlep15 © Steria Kravspesifikasjon
16
Hvorfor tester vi?
17
© Steria | 29/06/2014Presentation titlep17 © Steria Redde dårlig produkt?
18
© Steria | 29/06/2014Presentation titlep18 © Steria Finne feil?
19
© Steria | 29/06/2014Presentation titlep19 © Steria Kontrollere kvalitet?
20
© Steria | 29/06/2014Presentation titlep20 © Steria Skape tillit?
21
© Steria | 29/06/2014Presentation titlep21 © Steria Definere kvalitet.
22
© Steria | 29/06/2014Presentation titlep22 © Steria Krav Akseptanse Design Enhetstest Kode
23
Testers rolle
24
Eksempel: Signering
25
© Steria | 29/06/2014Presentation titlep25 © Steria Utvikler Produkteier Tester
26
© Steria | 29/06/2014Presentation titlep26 © Steria Utvikler Produkteier Tester Som en betaler, Ønsker jeg å signere mine oppdrag, Slik at ingen kan utgi seg for å være meg
27
© Steria | 29/06/2014Presentation titlep27 © Steria Utvikler Produkteier Tester Hva med både ok signerte og feilsignerte oppdrag i en fil?
28
© Steria | 29/06/2014Presentation titlep28 © Steria Utvikler Produkteier Tester Ummm...... (hjelp?)
29
© Steria | 29/06/2014Presentation titlep29 © Steria Utvikler Produkteier Tester Gitt at en fil med oppdrag 1 og 2 Og oppdrag 1 er korrekt signert Og oppdrag 2 er ikke er korrekt signert Når filen valideres Så skal oppdrag 1 behandles normalt Og kunden skal motta en kvittering med teksten oppdrag 2 avvist
30
© Steria FitNesse eksempel #1
31
© Steria FitNesse eksempel #1
32
© Steria | 29/06/2014Presentation titlep32 © Steria Utvikler Produkteier Tester Gitt at.... Når.... Så... Cucumber (rspec)
33
Eksempel: Yatzy
34
© Steria | 29/06/2014Presentation titlep34 © Steria Utvikler Produkteier Tester Fullt hus skal gi 25 poeng
35
© Steria
36
| 29/06/2014Presentation titlep36 © Steria Utvikler Produkteier Tester Fullt hus skal gi 25 poeng
37
© Steria | 29/06/2014Presentation titlep37 © Steria Utvikler Produkteier Tester Regnes det som fullt hus om fem dice har samme pipcount
38
© Steria | 29/06/2014Presentation titlep38 © Steria Utvikler Produkteier Tester WTF?!?
39
© Steria | 29/06/2014Presentation titlep39 © Steria Utvikler Produkteier Tester For eksempel fem 4-ere er ikke fullt hus Ok!
40
© Steria
42
Utviklers tester
43
Gode enhetstester er også krav
44
© Steria JUnit eksempel #3: Repository @Test public void shouldRetrieveSameInstanceForSameKey() throws Exception { Category inserted = new Category("A"); Serializable id = repository.insert(inserted); repository.flushChanges(); Category retrieved1 = repository.retrieve(Category.class, id); Category retrieved2 = repository.retrieve(Category.class, id); Category retrieved3 = repository.find(Category.class).iterator().next(); retrieved1.setCategoryName("Z"); assertEquals(retrieved1.getCategoryName(), retrieved2.getCategoryName()); assertEquals(retrieved1.getCategoryName(), retrieved3.getCategoryName()); }
45
© Steria @Test public void shouldRetrieveSameInstanceForSameKey() throws Exception { Category inserted = new Category("A"); Serializable id = repository.insert(inserted); repository.flushChanges(); Category retrieved1 = repository.retrieve(Category.class, id); Category retrieved2 = repository.retrieve(Category.class, id); Category retrieved3 = repository.find(Category.class).iterator().next(); retrieved1.setCategoryName("Z"); assertEquals(retrieved1.getCategoryName(), retrieved2.getCategoryName()); assertEquals(retrieved1.getCategoryName(), retrieved3.getCategoryName()); } JUnit eksempel #3: Repository When I change one instance Then the others should be updated, too Given a database with one category Given I retrieve this category several times
46
© Steria JUnit eksempel #3: Repository @Test public void uncommittedInsertsShouldBeInvisibleForOtherThreads() { repository.beginTransaction(); Category category = new Category("A"); repository.insert(category); repository.flushChanges(); assertNull(retrieveInNewThread(Category.class, category.getId())); repository.commit(); assertEquals(category, retrieveInNewThread(Category.class, category.getId())); }
47
© Steria JUnit eksempel #3: Repository @Test public void uncommittedInsertsShouldBeInvisibleForOtherThreads() { repository.beginTransaction(); Category category = new Category("A"); repository.insert(category); repository.flushChanges(); assertNull(retrieveInNewThread(Category.class, category.getId())); repository.commit(); assertEquals(category, retrieveInNewThread(Category.class, category.getId())); } Given I insert a new category while in a transaction When I retrieve the category from another thread Then I should not be able to see it When I commit the transaction When I retrieve the category from another thread Then I should be able to see it
48
© Steria JUnit eksempel #4: Websider @Test public void listProductsPageShouldShowAll() throws Exception { Product product1 = new Product(uniqueName("product"), 12300); Product product2 = new Product(uniqueName("product"), 300); repository.insertAll(product1, product2); repository.flushChanges(); tester.beginAt("/products/"); tester.assertTextInElement("products", product1.getProductName()); tester.assertTextInElement("products", product2.getProductName()); }
49
© Steria JUnit eksempel #4: Websider @Test public void listProductsPageShouldShowAll() throws Exception { Product product1 = new Product(uniqueName("product"), 12300); Product product2 = new Product(uniqueName("product"), 300); repository.insertAll(product1, product2); repository.flushChanges(); tester.beginAt("/products/"); tester.assertTextInElement("products", product1.getProductName()); tester.assertTextInElement("products", product2.getProductName()); } Then I should see both products Given two products with unique names in the database When I go to the /products/ web page
50
© Steria JUnit eksempel #5: Husk negative tester @Test public void priceMustBeNumeric() throws Exception { String oldName = uniqueName("product"); int oldPrice = 1234; Product product = new Product(oldName, oldPrice); Serializable id = repository.insert(product); repository.flushChanges(); tester.beginAt("/products/" + id + "/edit.html"); tester.setTextField("productName", uniqueName("product")); tester.setTextField("price", "this is not a price!"); tester.submit(); tester.assertMatchInElement("errorExplaination", "[Pp]rice.*numeric"); Product stored = repository.retrieve(Product.class, id); assertEquals(oldPrice, stored.getPrice()); assertEquals(oldName, stored.getProductName()); }
51
© Steria JUnit eksempel #5: Husk negative tester @Test public void priceMustBeNumeric() throws Exception { String oldName = uniqueName("product"); int oldPrice = 1234; Product product = new Product(oldName, oldPrice); Serializable id = repository.insert(product); repository.flushChanges(); tester.beginAt("/products/" + id + "/edit.html"); tester.setTextField("productName", uniqueName("product")); tester.setTextField("price", "this is not a price!"); tester.submit(); tester.assertMatchInElement("errorExplaination", "[Pp]rice.*numeric"); Product stored = repository.retrieve(Product.class, id); assertEquals(oldPrice, stored.getPrice()); assertEquals(oldName, stored.getProductName()); } Then I should see an error message Given a product in the database When I go to the /products/ /edit web page And I go change the price to a negative value And I press submit And the product should be unchanged in the database
52
© Steria | 29/06/2014Presentation titlep52 © Steria Utvikler Gitt at.... Når.... Så...
53
Test først gir godt design
54
© Steria JUnit eksempel #1: Yatzy histogram @Test public void simpleCategoriesShouldBeSumOfMatchingDice() {... } @Test public void smallStrait() {... } @Test public void largeStrait() {... } @Test public void threeOfAKind() {... }
55
© Steria JUnit eksempel #1: Yatzy histogram @Test public void threeOfAKind() { assertEquals(0, scoreFor("three_of_a_kind", 1, 1, 2, 2, 3)); assertEquals(3, scoreFor("three_of_a_kind", 1, 1, 1, 2, 3)); assertEquals(6, scoreFor("three_of_a_kind", 2, 2, 2, 3, 3)); assertEquals(9, scoreFor("three_of_a_kind", 1, 1, 3, 3, 3)); }
56
© Steria JUnit eksempel #1: Yatzy histogram @Test public void fullHouse() { assertEquals(0, scoreFor("full_house", 1, 1, 2, 2, 3)); assertEquals(0, scoreFor("full_house", 1, 1, 1, 2, 3)); assertEquals(25, scoreFor("full_house", 1, 1, 1, 2, 2)); assertEquals(25, scoreFor("full_house", 1, 1, 2, 2, 2)); assertEquals(25, scoreFor("full_house", 5, 5, 6, 6, 6)); }
57
© Steria JUnit eksempel #1: Yatzy histogram @Test public void histogramShouldReturnFrequencyOfEachDie() { int[] roll = { 1, 1, 2, 3, 4 }; int[] histogram = new ScoreCard().histogram(roll); assertEquals(7, histogram.length); assertEquals(-1, histogram[0]); assertEquals(2, histogram[1]); assertEquals(1, histogram[2]); assertEquals(1, histogram[3]); assertEquals(1, histogram[4]); assertEquals(0, histogram[5]); assertEquals(0, histogram[6]);
58
© Steria JUnit eksempel #1: Yatzy histogram scoreCalculators.put("four_of_a_kind", new ScoreCalculator() { @Override public int calculate(int[] histogram) { for (int i=0; i<histogram.length; i++) { if (histogram[i] >= 4) return i*4; } return 0; } });
59
© Steria JUnit eksempel #2: Session og transaksjoner public interface Repository { Serializable insert(Object entity); T retrieve(Class entityType, Serializable id); void update(Object entity); Collection find(Class entityType); void delete(Object entity); void flushChanges(); }
60
© Steria JUnit eksempel #2: Session og transaksjoner shouldRetrieveSeparateButEqualsAfterSessionFlush() shouldRetrieveSameInstanceForSameKey() rollbackShouldUndoInsertsDeletesAndUpdates() uncommittedInsertsShouldBeInvisibleForOtherThreads() uncommitedDeletesShouldBeInvisibleForOtherThreads() uncommitedUpdatesShouldBeInvisibleForOtherThreads()
61
© Steria JUnit eksempel #2: Session og transaksjoner public void startSession() { sessionForThread.set( new NestedChangeSet(permanentStore)); } public void beginTransaction() { this.transactionForThread.set( new NestedChangeSet(permanentStore)); getSession().setParent( this.transactionForThread.get()); }
62
© Steria Vedlikeholdbarhet
63
Andre typer tester
64
© Steria | 29/06/2014Presentation titlep64 © Steria Ron Jeffries Only test what you want to work
65
© Steria | 29/06/2014Presentation titlep65 © Steria Johannes Find the defect where it’s cheapest
66
© Steria
67
Hvordan gjøre det bra på eksamen
68
© Steria | 29/06/2014Presentation titlep68 © Steria Krav Akseptanse Design Enhetstest Kode
69
Start med fasiten
Liknende presentasjoner
© 2024 SlidePlayer.no Inc.
All rights reserved.