SlideShare a Scribd company logo
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

More Related Content

PPTX
Roy Osherove TDD From Scratch
PPT
Testing And Drupal
PPTX
Best practices unit testing
PDF
Unit Testing Best Practices
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
PPTX
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
PDF
Unit testing (workshop)
PDF
Working With Legacy Code
Roy Osherove TDD From Scratch
Testing And Drupal
Best practices unit testing
Unit Testing Best Practices
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Unit testing (workshop)
Working With Legacy Code

What's hot (20)

PDF
Unit Testing 101
PPTX
Working Effectively with Legacy Code
PPTX
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
PPTX
Mocking with Moq
PPTX
.Net Unit Testing with Visual Studio 2010
PDF
Unit Testing Done Right
PPT
Automated Unit Testing
ODP
Embrace Unit Testing
PPT
Nguyenvandungb seminar
PPTX
An Introduction to unit testing
PPTX
Practical unit testing tips
PDF
Workshop unit test
PPT
Xp Day 080506 Unit Tests And Mocks
PPTX
Unit test
PPTX
Unit Testing
PDF
Software Testing
PDF
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
PDF
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
PPTX
Understanding Unit Testing
PPTX
QA Best Practices
Unit Testing 101
Working Effectively with Legacy Code
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Mocking with Moq
.Net Unit Testing with Visual Studio 2010
Unit Testing Done Right
Automated Unit Testing
Embrace Unit Testing
Nguyenvandungb seminar
An Introduction to unit testing
Practical unit testing tips
Workshop unit test
Xp Day 080506 Unit Tests And Mocks
Unit test
Unit Testing
Software Testing
"Unit Testing for Mobile App" by Fandy Gotama (OLX Indonesia)
Tech In Asia PDC 2017 - Best practice unit testing in mobile apps
Understanding Unit Testing
QA Best Practices
Ad

Similar to Automation test (20)

PDF
Testing Django Applications
ODP
Grails unit testing
PPT
Pragmatic Parallels: Java and JavaScript
PPTX
Test driven development in .Net - 2010 + Eclipse
PPT
Unit testing
PPTX
Unit tests & TDD
PPTX
Test-Driven Development In Action
PPTX
Tdd is not about testing (OOP)
PPTX
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
PPTX
Coding Naked 2023
PPT
Working Effectively With Legacy Code
PDF
SELJE_Database_Unit_Testing_Slides.pdf
PPTX
Intro To Unit and integration Testing
PDF
Testing Experience - Evolution of Test Automation Frameworks
PPTX
TDD Best Practices
PPTX
Testing ASP.NET - Progressive.NET
PPTX
Java script unit testing
PPTX
Testing Ext JS and Sencha Touch
PPT
Acceptance Testing With Selenium
PPTX
Test driven development
Testing Django Applications
Grails unit testing
Pragmatic Parallels: Java and JavaScript
Test driven development in .Net - 2010 + Eclipse
Unit testing
Unit tests & TDD
Test-Driven Development In Action
Tdd is not about testing (OOP)
#DOAW16 - DevOps@work Roma 2016 - Testing your databases
Coding Naked 2023
Working Effectively With Legacy Code
SELJE_Database_Unit_Testing_Slides.pdf
Intro To Unit and integration Testing
Testing Experience - Evolution of Test Automation Frameworks
TDD Best Practices
Testing ASP.NET - Progressive.NET
Java script unit testing
Testing Ext JS and Sencha Touch
Acceptance Testing With Selenium
Test driven development
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
A Presentation on Artificial Intelligence
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation theory and applications.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Monthly Chronicles - July 2025
A Presentation on Artificial Intelligence
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation theory and applications.pdf

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…

Editor's Notes

  • #11: 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 …