automation test
Post on 01-Nov-2014
2.289 Views
Preview:
DESCRIPTION
TRANSCRIPT
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
top related