utomating tactically and strategically - fistb testing assembly | fistb testing...

62
Automating T actically and Stra tegically Alan Richar dson 4 www .eviltes ter .com 4 www .compendiumdev .co.uk 4 @eviltes ter TESTING ASSEMBL Y 09/2017, Helsinki

Upload: others

Post on 03-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating Tactically and StrategicallyAlan Richardson

4 www.eviltester.com

4 www.compendiumdev.co.uk

4 @eviltester

TESTING ASSEMBLY 09/2017, Helsinki

Page 2: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Do you automate tactically or strategically?

Page 3: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating Tactically allows us to move fast, and target immediate needs

Page 4: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating Strategically allows us to gain budget and support for longer

periods of work

Page 5: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

We may believe we are automating strategically but are actually automating

tactically

Page 6: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Combine tactical and strategic approaches to

better our testing efforts.

Page 7: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Secrets of Successful Practical Automating4 Get work done

4 Automate Flows

4 Multiple Abstractions

4 Abstract to libraries, not frameworks

Page 8: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Testing field argues about4 Testing vs Checking

4 You can't automate testing

"Test Automation" is contentious

Page 9: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

An Example

"Is what follows a Test?" ...

Page 10: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void createPreviewMVP() throws IOException {

String args[] = { new File(System.getProperty("user.dir"), "pandocifier.properties").getAbsolutePath()};

new PandocifierCLI().main(args);

String propertyFileName = args[0]; File propertyFile = new File(propertyFileName); PandocifierConfig config; config = new PandocifierConfigFileReader(). fromPropertyFile(propertyFile);

Assert.assertTrue(new File( config.getPreviewFileName()).exists());}

Page 11: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

An Example "Ce n'est pas un test", ...4 a Test, it says it is a @Test

4 an Automated Test, it checks something (file exists)

4 an Automated Test, it Asserts on the check

4 a Tool - I use it to automatically build one of my books

4 not an Application - it doesn't have a GUI or a standalone execution build

Page 12: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

This is automated execution of a

process

Page 13: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

We Automate Parts of our Development Process:

Coding, Checking, Asserting, ...

Page 14: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically
Page 15: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Tactical Reality - I don't really care, I just want to

get work doneSuggests we also have 'strategic

reality'

Page 16: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Tools vs Abstractions4 Gherkin

4 Specflow, Cucumber

- - - - - - - - - - - - - -

4 Gherkin is a DSL templating language

4 Specflow, Cucumber are template parsers

4 We have to create abstractions to fill in the gap

Page 17: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

E. W. Djkstra on Abstraction"The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise."

4 1972 ACM Turing Lecture: 'The Humble Programmer'

Page 18: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Regression TestingThe system rarely actually suffers

"Regression"

Page 19: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Continuous Condition Assertion4 TDD, ATDD, Automated execution

4 All of these provide an ongoing safety net which might mean we don't need to revisit areas in the future (if we also tested them)

4 They don't mean that we have 'tested' them now

Page 20: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Coverage - All coverage is Model Based4 Code coverage based on source code model

4 What about requirements, system interfaces, states, flows?

4 Code coverage is a useful metric for TDD coverage

4 coverage models based on risk

Page 21: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Tactical vs Strategic Automating

Strategic does not mean 'strategy document'

Page 22: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating as part of a Testing Strategy

Page 23: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating Tactically vs Strategically

What is Tactical? What is Strategic?

Solve a problem Agreed & Understood Goals

Short Term Long Term

Change as necessary Slower to Change

Your Time 'project' time

Page 24: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Warning - sometimes tactics look like strategy4 Use of Jenkins is not Continuous Integration

4 Cucumber/Specflow (Gherkin) != ATDD or BDD

4 Automated Deployments != Continuous Delivery

4 Containers != always good environment provision

4 Page Objects != always good system abstractions

Page 25: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

You know you are Automating strategically when...4 Reduced Maintenance & Change

4 Everyone agrees why

4 No fighting for 'time'

4 It's not about roles

4 It gets done

Page 26: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

How do we automate?4 not about "test automation"

4 it is about automating tasks

4 automate the assertions used to check that the stories are still 'done'

Page 27: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automate flows through the system

- vary data

- abstract the execution

Page 28: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating Strategically with Abstractionssee also "Domain Driven Design"

"modeling the system in code"

4 abstractions are about modelling - people seem to be scared of having too many models

Page 29: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

No Abstractions - Web Testing Example

Page 30: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void canCreateAToDoWithNoAbstraction(){ WebDriver driver = new FirefoxDriver(); driver.get("http://todomvc.com/architecture-examples/backbone/");

int originalNumberOfTodos = driver.findElements( By.cssSelector("ul#todo-list li")).size(); WebElement createTodo = driver.findElement(By.id("new-todo")); createTodo.click(); createTodo.sendKeys("new task"); createTodo.sendKeys(Keys.ENTER); assertThat(driver.findElement(By.id("filters")).isDisplayed(), is(true));

int newToDos = driver.findElements( By.cssSelector("ul#todo-list li")).size(); assertThat(newToDos, greaterThan(originalNumberOfTodos));}

Page 31: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

But there were Abstractions (Lots of them)

4 WebDriver - abstration of browser

4 FirefoxDriver - abstraction Firefox (e.g. no version)

4 WebElement - abstraction of a dom element

4 createToDo - variable - named for clarity

4 Locator Abstractions via methods e.g. findElement

4 Manipulation Abstractions .sendKeys

4 Locator Strategies By.id

Page 32: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Using Abstractions - Same flow

Page 33: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void canCreateAToDoWithAbstraction(){ TodoMVCUser user = new TodoMVCUser(driver, new TodoMVCSite());

user.opensApplication().and().createNewToDo("new task");

ApplicationPageFunctional page = new ApplicationPageFunctional(driver, new TodoMVCSite()); assertThat(page.getCountOfTodoDoItems(), is(1)); assertThat(page.isFooterVisible(), is(true));}

Page 34: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

What Abstractions were there?4 TodoMVCUser

4 User

4 Intent/Action Based

4 High Level

4 ApplicationPageFunctional

4 Structural

4 Models the rendering of the application page

Page 35: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

REST Test - No Abstractions

Page 36: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void aUserCanAccessWithBasicAuthHeader(){

given(). contentType("text/xml"). auth().preemptive().basic( TestEnvDefaults.getAdminUserName(), TestEnvDefaults.getAdminUserPassword()). expect(). statusCode(200). when(). get(TestEnvDefaults.getURL().toExternalForm() + TracksApiEndPoints.todos);}

Page 37: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

But there were Abstractions4 RESTAssured - given, when, then, expect, auth, etc.

4 RESTAssured is an abstraction layer

4 Environment abstractions i.e. TestEnvDefaults

Lots of Abstractions

But a lack of flexibility

Page 38: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Different abstractions to support flexibility

Page 39: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void aUserCanAuthenticateAndUseAPI(){

HttpMessageSender http = new HttpMessageSender( TestEnvDefaults.getURL());

http.basicAuth( TestEnvDefaults.getAdminUserName(), TestEnvDefaults.getAdminUserPassword());

Response response = http.getResponseFrom( TracksApiEndPoints.todos);

Assert.assertEquals(200, response.getStatusCode());}

Page 40: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

An API Abstraction

Page 41: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

@Testpublic void aUserCanAuthenticateAndUseAPI(){

TodosApi api = new TodosApi( TestTestEnvDefaults.getURL(), TestEnvDefaults.getUser());

Response response = api.getTodos();

Assert.assertEquals(200, response.getStatusCode());}

Page 42: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automating API vs GUI

Page 43: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Automate at the interfaces where you can interact with the system.

Page 44: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Architecting to Support...

- Testing - Support

- Deployment - Automating

- Monitoring - Devops

- Releasing - etc.

Page 45: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Abstractions support different types of testing4 regular automated execution with assertions

4 creation and maintenance by many roles

4 exploratory testing

4 stress/performance testing (bot example) requires thread safe abstractions

Page 46: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Good abstractions encourage creativity, they do not force compliance and

restrict flexibility.

Page 47: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Supports Law of Requisite Variety

"only variety can destroy variety" - W. Ross Ashby

"only variety can absorb variety" - Stafford Beer

Page 48: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Frameworks can 'Destroy' variety4 Frameworks force us to comply with their structure

4 or things get 'hard'

4 or we don't reap the benefits from the Framework

4 Some things are not possible

4 Some things never occur to you to do

Page 49: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

We have a lot of models4 user intent model - what I want to achieve

4 user action model - how I do that

4 interface messaging model - how the system implements that

4 admin models, support models, GUI models

Page 50: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

And models overlape.g. user can use the API or the GUI to

do the same things

Page 51: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

When we don't do this4 test code takes a long time to maintain

4 test code takes too long to write

4 test code is hard to understand

4 test code is brittle - "every time we change the app the tests break/ we have to change test code"

4 execution is flaky - intermittent test runs - "try running the tests again"

Page 52: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Example: Tactical Approach on Agile projects4 exploratory testing to get the story to done

4 create a tech debt backlog for 'missing' automated tests

4 @Test code is tactical and we can knock it up (not as good as production)

Page 53: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Example: Strategic Approach on Agile Projects4 automate assertion checking of acceptance criteria for "done"

4 ongoing execution of the assertions for the life of the story

Page 54: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Example: Strategic Approach on Agile Projects implies...4 maintained for the life of the story in the application

4 deleting the @Test code when no longer relevant

4 amending code structure to make relevant as stories change and evolve

4 @Test code is strategic asset ( just like production code)

Page 55: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Why labour the point?4 "test automation" often means "testers do the

automating"

4 testers may not program as well as programmers

4 testers may not know various programming patterns

4 when programmers see @Test code written by testers they often don't want to touch it or maintain it

Page 56: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Move from Abstractions such as 'Programming' and 'Testing' to 'Developing'

Page 57: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

I say I'm a "Test Consultant"

I'm really a "Software Development Consultant"

Testing is Part of the Development process

Page 58: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Summary4 Automate Strategically

4 ongoing assertion checking automated in @Test code

4 Abstractions model the system in code

4 Write abstractions at multiple levels

4 Good abstractions can support exploratory testing

4 Write good code all the time

Page 59: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Learn to "Be Evil"4 www.eviltester.com

4 @eviltester

4 www.youtube.com/user/EviltesterVideos

Page 60: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Learn About Alan Richardson4 www.compendiumdev.co.uk

4 uk.linkedin.com/in/eviltester

Page 61: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

Follow4 Linkedin - @eviltester

4 Twitter - @eviltester

4 Instagram - @eviltester

4 Facebook - @eviltester

4 Youtube - EvilTesterVideos

4 Pinterest - @eviltester

4 Github - @eviltester

Page 62: utomating Tactically and Strategically - FiSTB Testing Assembly | FiSTB Testing …testingassembly.fistb.fi/sites/testingassemblyfistb/... · 2017-09-21 · Automating Tactically

BIOAlan is a test consultant who enjoys testing at a technical level using techniques from psychotherapy and computer science. Alan is the author of the books "Dear Evil Tester", "Java For Testers" and "Automating and Testing a REST API". Alan's main website is compendiumdev.co.uk and he blogs at blog.eviltester.com (see also TesterHQ.com)