Automated Testing
A software adventure
https://www.flickr.com/photos/nancyvioletavelez/
Hello World
Infinite possibility.
That Escalated Quickly
https://www.flickr.com/photos/aigle_dore/
At some point we realize that there is uncertainty.
Is it going to break?
Software
Is
Hard :(
Testing can tell you exactly what will break and where.
Think of it like a contract with your product.
An agreement on function.
How does it work?
Tests are simply expectations of how your code is supposed to work. If your expectation is met, then the test passes. Otherwise, it fails.
Think
Long
Term
https://www.flickr.com/photos/patt-ach/
Case Study #1
Testing All The Things
JavaScript
Selenium
Sauce Labs
Python
Jasmine
PhantomJS
Expensive to write.
--------------
--------------
Cheap to write
run
maintain
get results
maintain
run
get results
https://www.flickr.com/photos/calsidyrose/
Unit Test
Integration Test
it("should detect an empty object", function(){
expect(Util.isEmptyObject({})).toEqual(true);
expect(Util.isEmptyObject({name:"ricky"})).toEqual(false);
});
@Test
public void noApiKey() {
final String actualResponse = getResponse(RULE, "/nitro", String.class);
String expected = "{\"status\":\"error\",\"message\":\"apiKey parameter is required\"}";
assertThat("The /nitro should complain about apiKey", actualResponse,
is(equalTo(expected)));
}
Lesson Learned
The 90-10 Rule
Leverage unit test for 90% of your test coverage
Leverage integration tests for 10% of your test coverage (SMOKE TEST)
https://www.flickr.com/photos/vonlind/
What We Had
What We Needed
Case Study #2
Test Some of The Things
Existing Monolithic Application
No Documentation
https://www.flickr.com/photos/calsidyrose/
Per page of our app
1. Document functionality
2. Agree to functionality across teams
3. Write Manual Tests
4. Evaluate to see if we can automate it
Don't do it all at once. Iterate on it. We created a ticket for each page. We pull a few in each iteration. This way we are not completely blocking our product to market pipeline.
https://www.flickr.com/photos/texturetime/
What to test?
- Define your expectations. Your contract.
- Does this contract reflect what we are selling?
- Test YOUR code, not third party code.
- Business logic
- start with mission critical functions
- If your function has an "if", test all cases
- handle bad input
- edge cases
https://www.flickr.com/photos/30127497@N04/
Where to start?
- Fixing a bug?
- Write a test that confirms the bug.
- Fixing the code will make the test pass.
- Writing new functionality? Write tests.
- When updating legacy code. Write tests.
- Test Driven Development?
- We want a test suite that reflects the contract.
- Doesn't matter how you get there.
https://www.flickr.com/photos/30127497@N04/
Jasmine Examples
define([
'jquery'
], function($) {
describe("Namespacing", function(){
it("window.$ should not be defined", function(){
expect(window.$).toEqual(null);
});
it("window.jQuery should not be defined", function(){
expect(window.jQuery).toEqual(null);
})
});
});
más ejemplos
it("should detect email address", function() {
expect(Util.isEmail("ricky@ricardo.com")).toEqual(true);
expect(Util.isEmail("234")).toEqual(false);
expect(Util.isEmail("1@1.1")).toEqual(false);
expect(Util.isEmail("ricky.guy@ricardo.com")).toEqual(true);
});
it("should detect an empty object", function(){
expect(Util.isEmptyObject({})).toEqual(true);
expect(Util.isEmptyObject({name:"ricky"})).toEqual(false);
});
// Ought to be named stripAngleBrackets
it("should strip angle brackets", function(){
expect(Util.stripHTML("<h1>")).toEqual('h1');
});
it("should escape HTML", function(){
expect(Util.escapeHTML("<h1>Page Title</h1>")).toEqual('<h1>Page Title</h1>');
});
it("should escape double qoutes", function() {
expect(Util.escapeDoubleQuotes("So I says to him, \" Walt! \""))
.toEqual('So I says to him, " Walt! "');
});
How is this automated?
Git Hook
<target name="runJasmineTests">
<property name="specrunner.dir" location="./${test.dir}"/>
<exec executable="phantomjs" newenvironment="false"
dir="./${test.dir}" failonerror="true" osfamily="unix">
<arg value="run-jasmine.js"/>
<arg line="${specrunner.dir}/SpecRunner.html" />
</exec>
</target>
Jasmine Ant Task
Jenkins Config
"Speed is the new currency of development"
Dreamforce
photo by Sean Turbidy
The Advantage
Releasing often while maintaining quality
Its not just about SPEED to Market. Its maintaining QUALITY over time.
https://www.flickr.com/photos/skipmoore/
The
End
https://www.flickr.com/photos/ifindkarma/
deck
By bozzltron
deck
- 1,113