1. AMIR BARYLKO
EASY
AUTOMATION
FOR EVERY DAY
PROJECTS
WINNIPEG CODE CAMP
FEB 2011
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
2. WHO AM I?
• Quality Expert
• Architect
• Developer
• Mentor
• Great cook
• The one who’s entertaining you for the next hour!
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
3. RESOURCES
• Email: amir@barylko.com
• Twitter: @abarylko
• Blog: http://www.orthocoders.com
• Materials: http://www.orthocoders.com/presentations
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
4. WHO NEEDS
AUTOMATION?
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
5. EVERY DAY PROJECT SETUP
• Repetitive task (project structure, scripts, etc)
• Source control setup
• Testing setup
• Database setup
• Deployment setup
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
6. MANUAL SETUP
• Get the last project, copy, paste & delete
• Use documentation and follow instructions (ha! good one!)
• Use the IDE to build
• Copy the assemblies, etc to where
• Database connection centralized or hardcoded
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
7. WHAT’S WRONG?
• Lengthy process (waste) • Very hard to maintain
• Hard to reproduce • Complex for larger teams
• Usually no documented • Hard to deploy
• The architect just moved to • High dependency with the
another country IDE
• Coupled to the environment
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
8. WHAT TO DO?
• Avoid It works on my • Scripts for every task!
computer!
• Continuous integration
• Use application skeletons
• TDD & BDD
• End to end setup from day
one! • Clear
feature development
process
• Always in deliverable state
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
9. ONE STEP AT A TIME
Project skeleton
Build Automation
Test Automation
CI setup
Push Changes (commit)
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
11. FOLDER STRUCTURE
• MediaLibrary
--- MavenThought.MediaLibrary.sln : Main solution file
--- Rakefile: Main rake file to launch build, test, etc.
+-- main: Project files (sources)
+-- test: Test project files
+-- features: Features used by Capybara + Cucumber
+-- lib2: Dependencies that can't be installed with bundler
+-- tools: Tools used to run tests, xslt, etc.
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
14. ARE YOU NUTS? RUBY?
• The best tool for the job
• What does it mean to be a developer?
• Ruby is a great scripting language
• Need something? There is a gem for that....
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
15. RAKE
• Domain Specific Language
• Great, great, great .... grandchild of make
• Is just Ruby
• Lots of gems (libraries) available
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
16. ALBACORE
• Basic functionality for .NET projects
• OpenSource
• Active Development
• Very easy to use
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
17. BASIC RAKEFILE
require 'rubygems'
require 'albacore'
require 'rake/clean'
include FileUtils
solution_file = FileList["*.sln"].first
project_name = "MavenThought.MovieLibrary"
CLEAN.include("main/**/bin", "main/**/obj", "test/**/obj", "test/**/bin")
CLOBBER.include("**/_*", "lib/*", "**/*.user", "**/*.cache", "**/*.suo")
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
18. BASIC RAKEFILE II
desc 'Default build'
task :default => ["build:all"]
namespace :build do
desc "Build the project"
msbuild :all, :config do |msb, args|
msb.properties :configuration => args[:config] || :Debug
msb.targets :Build
msb.solution = solution_file
end
desc "Rebuild the project"
task :re => ["clean", "build:all"]
end
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
20. MANY OPTIONS
• Store dependencies in source control (not recommended)
• Use Nuget and then store them in SC
• Use openwrap
• Use gems + bundler
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
21. BUNDLER
• Define Gemfile with dependencies
• Run “bundle install”
• Create task to setup .NET dependencies under lib
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
22. GEMFILE
source :rubygems
group :setup do
gem 'albacore'
gem 'git'
gem 'noodle'
end
group :dev do
gem 'sharptestsex'
gem 'gallio', '~> 3.2'
gem 'rhino.mocks', '~> 3.6'
gem 'structuremap.automocking', '~> 2.6.1.1'
gem 'maventhought.testing'
gem 'maventhought.commons'
end
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
23. COPY LOCAL
DEPENDENCIES
desc 'Setup requirements to build and deploy'
task :setup => ["setup:dep:local"]
namespace :setup do
namespace :dep do
Noodle::Rake::NoodleTask.new :local do |n|
n.groups << :runtime
n.groups << :dev
end
end
end
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
25. UNIT TESTS
• Each project has a separate testing project
• Clear naming convention (MavenThought.Core.Tests)
• Enforce TDD when possible
• Automate since day one (even with empty tests)
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
26. RUN TESTS
desc "Run all tests"
task :test => ["test:all"]
namespace :test do
desc 'Run all tests'
task :all => [:default] do
tests = FileList["test/**/bin/debug/**/*.Tests.dll"].join " "
system "./tools/gallio/bin/gallio.echo.exe #{tests}"
end
end
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
28. BENEFITS OF CI
• Integrate code frequently
• Trigger events (deployment, etc)
• Validate build
• Regression tests (unit, integration, acceptance)
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
29. MANY OPTIONS
TeamCity
•Team System Build server
•Hudson
•CruiseControl.NET
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
30. TEAM CITY
• Very easy to use
• Free for 20 projects & 3 agents
• Web Based
• Awesome UI
• Supports: Rake, MsBuild, Nant, etc....
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
32. CLEAR PROCESS
• Branch per feature
• Commit often
• Merge changes from trunk often
• Automate commit (to avoid mistakes)
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
33. GOING ALL THE WAY
Static Analysis Tools
Deployment
Acceptance Tests Automation
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
35. STATIC ANALYSIS
• StyleCop
• FxCop
• Code Coverage
• Dependencies
• Simian
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
36. STYLECOP
namespace :tools do
desc "Runs stylecop and generates a report on the Output folder"
task :stylecop do
mkdir "Output" unless File.directory? "Output"
stylecop = "tools/stylecopcmd/StyleCopCmd"
# Run the StyleCopCmd from tools
sh "#{stylecop} -sf #{solution_file} -ifp AssemblyInfo.cs -of..."
sh "tools/Xslt/msxsl.exe Output/stylecop.violations.xml ...."
xmldoc = Document.new(File.new("Output/stylecop.violations.xml"))
violations = XPath.first(xmldoc, "/StyleCopViolations/Violation")
abort "Stylecop Failed!" unless violations.nil?
end
end
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
38. ASSEMBLY VERSION
• Use SVN revision
• Combine Major.Minor.Build.Revision
• Update AssemblyInfo.cs
• Build in release
• Deploy to a folder as a zipfile
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011
40. RUNNING CUCUMBER
• Start the server
• Setup database
• Run the scenario
• Stop the server
Amir Barylko - CodeCamp 2011 MavenThought Inc.
Sunday, February 27, 2011