SlideShare uma empresa Scribd logo
1 de 23
Automation
   Test
   余昭辉
   2011.10
I’m a…

   Developer(C#, Java, Scala…)

   Blogger(http://yuyijq.cnblogs.com)

   Microsoft MVP(C#)



I like…

   CLR, JVM

   OO, Design Pattern, Clean Code

   Agile(TDD, Code Review, Pair
    Programming, etc)
Tools
jUnit

   Test Fixture
       BeforeClass, AfterClass, Before, After,
        assumeThat, Group Tests

   Extensions
       DbUnit, jsonAssert

   Hamcres
       Matchers
       More expression
       Friendly assert result
Mock

   Mockito

   jMock

   easyMock

   MockObjects
Spring test

   MockHttpServletRequest

   MockHttpServletResponse

   MockHttpSession

   MockServletConfig

   MockServletContext

   …

   ModelAndViewAssert
Selenium + WebDriver

   driver.get(“http://www.qunar.com”)

   driver.findElement(By.id(“login”)).click();

   …
BDD(Cucumber)

   How to manage test cases?

   The relation between test cases and test
    code.

   QA and Dev
Principles
Test is a feedback
mechanism

   Run fast

   Run after each modified

   Run before check-in

   …
Test triangle


 Functional Tests




Integration Tests



Unit Tests
State-based assert over
behavior-based assert

   assertThat(service.findById(1),is(expected))

   verify(service,times(1)).findById(1);
assertThat over assertXxx

   Self description

   Different parameter type
Test behavior, not methods

   One behavior, one test

   Not one method many tests

   One test one assert(*)
Test method name is
important

   Test method is document

   Give your intent:
       testFindById is not a good name
       should_find_agent_by_id is better
       TestDox rule
Test data builder

   Agent agent = new AgentBuilder().build();
Repeat run

   Don’t modified database, transaction

   Prepare data itself, or write fixture
Test code is as important as
product code

   We should extract duplicate code to method

   We should use good names

   …
Add test at:

   If you want to add println to get debug info

   If you find a bug, write a test first
Test as singal

   It’s very difficult to test

   Three steps:
       Given
       When
       Then

   Test private methods
Demo
Remember

   Automated test can’t avoid bugs

   Even it can’t help you find bugs

   But it can avoid introduce bugs

   But…
Thank you

Mais conteúdo relacionado

Mais procurados

An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
Steven Casey
 

Mais procurados (20)

Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 
Working Effectively with Legacy Code
Working Effectively with Legacy CodeWorking Effectively with Legacy Code
Working Effectively with Legacy Code
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Mocking with Moq
Mocking with MoqMocking with Moq
Mocking with Moq
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 
Unit Testing Done Right
Unit Testing Done RightUnit Testing Done Right
Unit Testing Done Right
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Practical unit testing tips
Practical unit testing tipsPractical unit testing tips
Practical unit testing tips
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)"Unit Testing for Mobile App" by Fandy Gotama  (OLX Indonesia)
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
 
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile appsTech In Asia PDC 2017 - Best practice unit testing in mobile apps
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
QA Best Practices
QA  Best PracticesQA  Best Practices
QA Best Practices
 

Semelhante a Automation test

Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
elliando dias
 

Semelhante a Automation test (20)

Testing Django Applications
Testing Django ApplicationsTesting Django Applications
Testing Django Applications
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases#DOAW16 - DevOps@work Roma 2016 - Testing your databases
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
 
Coding Naked 2023
Coding Naked 2023Coding Naked 2023
Coding Naked 2023
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
Intro To Unit and integration Testing
Intro To Unit and integration TestingIntro To Unit and integration Testing
Intro To Unit and integration Testing
 
Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Testing Ext JS and Sencha Touch
Testing Ext JS and Sencha TouchTesting Ext JS and Sencha Touch
Testing Ext JS and Sencha Touch
 
Acceptance Testing With Selenium
Acceptance Testing With SeleniumAcceptance Testing With Selenium
Acceptance Testing With Selenium
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Automation test

  • 1. Automation Test 余昭辉 2011.10
  • 2. I’m a…  Developer(C#, Java, Scala…)  Blogger(http://yuyijq.cnblogs.com)  Microsoft MVP(C#) I like…  CLR, JVM  OO, Design Pattern, Clean Code  Agile(TDD, Code Review, Pair Programming, etc)
  • 4. jUnit  Test Fixture  BeforeClass, AfterClass, Before, After, assumeThat, Group Tests  Extensions  DbUnit, jsonAssert  Hamcres  Matchers  More expression  Friendly assert result
  • 5. Mock  Mockito  jMock  easyMock  MockObjects
  • 6. Spring test  MockHttpServletRequest  MockHttpServletResponse  MockHttpSession  MockServletConfig  MockServletContext  …  ModelAndViewAssert
  • 7. Selenium + WebDriver  driver.get(“http://www.qunar.com”)  driver.findElement(By.id(“login”)).click();  …
  • 8. BDD(Cucumber)  How to manage test cases?  The relation between test cases and test code.  QA and Dev
  • 10. Test is a feedback mechanism  Run fast  Run after each modified  Run before check-in  …
  • 11. Test triangle Functional Tests Integration Tests Unit Tests
  • 12. State-based assert over behavior-based assert  assertThat(service.findById(1),is(expected))  verify(service,times(1)).findById(1);
  • 13. assertThat over assertXxx  Self description  Different parameter type
  • 14. Test behavior, not methods  One behavior, one test  Not one method many tests  One test one assert(*)
  • 15. Test method name is important  Test method is document  Give your intent:  testFindById is not a good name  should_find_agent_by_id is better  TestDox rule
  • 16. Test data builder  Agent agent = new AgentBuilder().build();
  • 17. Repeat run  Don’t modified database, transaction  Prepare data itself, or write fixture
  • 18. Test code is as important as product code  We should extract duplicate code to method  We should use good names  …
  • 19. Add test at:  If you want to add println to get debug info  If you find a bug, write a test first
  • 20. Test as singal  It’s very difficult to test  Three steps:  Given  When  Then  Test private methods
  • 21. Demo
  • 22. Remember  Automated test can’t avoid bugs  Even it can’t help you find bugs  But it can avoid introduce bugs  But…

Notas do Editor

  1. If you modified some code, ensure you don’t break the test, if you break some tests, please fix it as quick as possible. You mustn’t leave the fail test to …