diff --git a/.travis.yml b/.travis.yml
index 4a3da039ecd506a6e0eae5c0ad1e42e397e26a9b..ecfad5326a4d72d44549452c33106751aaff2f62 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,13 +2,6 @@ language: ruby
 rvm: 2.0.0
 os: linux
 
-matrix:
-  include:
-    - os: osx
-      env: OSX=10.11
-      osx_image: xcode7.3
-      rvm: system
-
 before_install:
   - export HOMEBREW_DEVELOPER=1
   - export PATH="bin:$PATH"
diff --git a/Library/Homebrew/cask/Gemfile b/Library/Homebrew/cask/Gemfile
index c164a3f670d1c8d945c864d0b8171fccb0e8b1b7..af1c8d3bc652482a60d4d7e616d804723b004222 100644
--- a/Library/Homebrew/cask/Gemfile
+++ b/Library/Homebrew/cask/Gemfile
@@ -12,7 +12,7 @@ group :development do
 end
 
 group :test do
-  gem "coveralls", require: false
+  gem "codecov", require: false
   gem "minitest", "5.4.1"
   gem "minitest-reporters"
   gem "mocha", "1.1.0", require: false
diff --git a/Library/Homebrew/cask/Gemfile.lock b/Library/Homebrew/cask/Gemfile.lock
index b65784444f902d22ec8a11076d3e9bdfaffac79f..c9c2b5cca9d5bcd38807bd0c6d33506e7eb17d0e 100644
--- a/Library/Homebrew/cask/Gemfile.lock
+++ b/Library/Homebrew/cask/Gemfile.lock
@@ -5,13 +5,11 @@ GEM
     ast (2.3.0)
     builder (3.2.2)
     byebug (9.0.5)
+    codecov (0.1.5)
+      json
+      simplecov
+      url
     coderay (1.1.1)
-    coveralls (0.8.15)
-      json (>= 1.8, < 3)
-      simplecov (~> 0.12.0)
-      term-ansicolor (~> 1.3)
-      thor (~> 0.19.1)
-      tins (>= 1.6.0, < 2)
     diff-lcs (1.2.5)
     docile (1.1.5)
     json (2.0.2)
@@ -71,17 +69,14 @@ GEM
       simplecov-html (~> 0.10.0)
     simplecov-html (0.10.0)
     slop (3.6.0)
-    term-ansicolor (1.3.2)
-      tins (~> 1.0)
-    thor (0.19.1)
-    tins (1.12.0)
     unicode-display_width (1.1.0)
+    url (0.3.2)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
-  coveralls
+  codecov
   minitest (= 5.4.1)
   minitest-reporters
   mocha (= 1.1.0)
diff --git a/Library/Homebrew/cask/README.md b/Library/Homebrew/cask/README.md
index 35fe201a5d16954fc0278cc76df989c7e5fc8b25..1d0dc5882acfb610ff69e2d5ab34be3e69e036b5 100644
--- a/Library/Homebrew/cask/README.md
+++ b/Library/Homebrew/cask/README.md
@@ -8,9 +8,6 @@ We do this by providing a friendly Homebrew-style CLI workflow for the administr
 
 It鈥檚 implemented as a `homebrew` [external command](https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/External-Commands.md) called `cask`.
 
-[![Build Status](https://img.shields.io/travis/caskroom/homebrew-cask/master.svg)](https://travis-ci.org/caskroom/homebrew-cask)
-[![Code Climate](https://img.shields.io/codeclimate/github/caskroom/homebrew-cask.svg)](https://codeclimate.com/github/caskroom/homebrew-cask)
-[![Coverage Status](https://img.shields.io/coveralls/caskroom/homebrew-cask.svg)](https://coveralls.io/r/caskroom/homebrew-cask)
 [![Join the chat at https://gitter.im/caskroom/homebrew-cask](https://img.shields.io/badge/gitter-join%20chat-blue.svg)](https://gitter.im/caskroom/homebrew-cask)
 
 ## Let鈥檚 try it!
diff --git a/Library/Homebrew/cask/Rakefile b/Library/Homebrew/cask/Rakefile
index 7a276b347b4c0662ad2d0543e75b0a6265b1d77c..25deee40716b21d30a8eca33493e58d28a268b28 100644
--- a/Library/Homebrew/cask/Rakefile
+++ b/Library/Homebrew/cask/Rakefile
@@ -23,10 +23,11 @@ namespace :test do
 
     Rake::Task[:test].invoke
 
-    if ENV["TRAVIS"]
-      require "coveralls/rake/task"
-      Coveralls::RakeTask.new
-      Rake::Task['coveralls:push'].invoke
+    if ENV["CODECOV_TOKEN"]
+      require "simplecov"
+      require "codecov"
+      formatter = SimpleCov::Formatter::Codecov.new
+      formatter.format(SimpleCov::ResultMerger.merged_result)
     end
   end
 end
diff --git a/Library/Homebrew/dev-cmd/test-bot.rb b/Library/Homebrew/dev-cmd/test-bot.rb
index ed803d7fc4a8d36077141824cc49ff63680a30f3..1a209506839a5a2dda937f1b3ee185eae36eb901 100644
--- a/Library/Homebrew/dev-cmd/test-bot.rb
+++ b/Library/Homebrew/dev-cmd/test-bot.rb
@@ -59,8 +59,7 @@
 #:
 #:    If `--no-pull` is passed, don't use `brew pull` when possible.
 #:
-#:    If `--coverage` is passed, generate coverage report and send it to
-#:    Coveralls.
+#:    If `--coverage` is passed, generate and uplaod a coverage report.
 #:
 #:    If `--test-default-formula` is passed, use a default testing formula
 #:    when not building a tap and no other formulae are specified.
@@ -72,6 +71,9 @@
 #:
 #:    If `--ci-testing` is passed, use the Homebrew testing CI options.
 #:
+#:    If `--ci-auto` is passed, automatically pick one of the Homebrew CI
+#:    options based on the environment.
+#:
 #:    If `--ci-upload` is passed, use the Homebrew CI bottle upload
 #:    options.
 #:
@@ -709,18 +711,24 @@ module Homebrew
       return if @skip_homebrew
 
       if !@tap && (@formulae.empty? || @test_default_formula)
-        tests_args = ["--official-cmd-taps"]
-        tests_args_no_compat = []
-        tests_args_no_compat << "--coverage" if ARGV.include?("--coverage")
-        test "brew", "tests", *tests_args
-        test "brew", "tests", "--generic", *tests_args
-        test "brew", "tests", "--no-compat", *tests_args_no_compat
+        coverage_args = []
+        if ARGV.include?("--coverage")
+          if ENV["JENKINS_HOME"]
+            if OS.mac? && MacOS.version == :el_capitan
+              coverage_args << "--coverage"
+            end
+          else
+            coverage_args << "--coverage"
+          end
+        end
+
+        test "brew", "tests", "--no-compat"
+        test "brew", "tests", "--generic"
+        test "brew", "tests", "--official-cmd-taps", *coverage_args
         test "brew", "readall", "--syntax"
         if OS.mac?
           run_as_not_developer { test "brew", "tap", "caskroom/cask" }
-          tests_args_cask = []
-          tests_args_cask << "--coverage" if ARGV.include?("--coverage")
-          test "brew", "cask-tests", *tests_args_cask
+          test "brew", "cask-tests", *coverage_args
         end
 
         # TODO: try to fix this on Linux at some stage.
@@ -1003,16 +1011,29 @@ module Homebrew
     ENV["HOMEBREW_FAIL_LOG_LINES"] = "150"
     ENV["HOMEBREW_EXPERIMENTAL_FILTER_FLAGS_ON_DEPS"] = "1"
 
-    if ENV["TRAVIS"]
+    travis = !ENV["TRAVIS"].nil?
+    if travis
       ARGV << "--verbose"
-      ARGV << "--ci-master" if ENV["TRAVIS_PULL_REQUEST"] == "false"
       ENV["HOMEBREW_VERBOSE_USING_DOTS"] = "1"
+    end
+
+    # Only report coverage if build runs on macOS and this is indeed Homebrew,
+    # as we don't want this to be averaged with inferior Linux test coverage.
+    if OS.mac? && (ENV["COVERALLS_REPO_TOKEN"] || ENV["CODECOV_TOKEN"])
+      ARGV << "--coverage"
+    end
 
-      # Only report coverage if build runs on macOS and this is indeed Homebrew,
-      # as we don't want this to be averaged with inferior Linux test coverage.
-      repo = ENV["TRAVIS_REPO_SLUG"]
-      if repo && repo.start_with?("Homebrew/") && ENV["OSX"]
-        ARGV << "--coverage"
+    travis_pr = ENV["TRAVIS_PULL_REQUEST"] && ENV["TRAVIS_PULL_REQUEST"] != "false"
+    jenkins_pr = !ENV["ghprbPullLink"].nil?
+    jenkins_branch = !ENV["GIT_COMMIT"].nil?
+
+    if ARGV.include?("--ci-auto")
+      if travis_pr || jenkins_pr
+        ARGV << "--ci-pr"
+      elsif travis || jenkins_branch
+        ARGV << "--ci-master"
+      else
+        ARGV << "--ci-testing"
       end
     end
 
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile
index df6429f501599662d2993d67a8eb2d2b89f8a832..c7c14623347030093804e99d3691f062e24db1cd 100644
--- a/Library/Homebrew/test/Gemfile
+++ b/Library/Homebrew/test/Gemfile
@@ -13,5 +13,5 @@ group :coverage do
     :git => "https://github.com/colszowka/simplecov.git",
     :branch => "master", # commit 257e26394c464c4ab388631b4eff1aa98c37d3f1
     :require => false
-  gem "coveralls", "0.8.14", :require => false
+  gem "codecov", require: false
 end
diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock
index 2e78f050b1680b7eb5c77c44c47516a0a22d3c61..ceb11128dcf9b099511d099dcb6f5bc8b51d9e76 100644
--- a/Library/Homebrew/test/Gemfile.lock
+++ b/Library/Homebrew/test/Gemfile.lock
@@ -11,12 +11,10 @@ GIT
 GEM
   remote: https://rubygems.org/
   specs:
-    coveralls (0.8.14)
-      json (>= 1.8, < 3)
-      simplecov (~> 0.12.0)
-      term-ansicolor (~> 1.3)
-      thor (~> 0.19.1)
-      tins (~> 1.6.0)
+    codecov (0.1.5)
+      json
+      simplecov
+      url
     docile (1.1.5)
     json (1.8.3)
     metaclass (0.0.4)
@@ -25,16 +23,13 @@ GEM
       metaclass (~> 0.0.1)
     rake (10.5.0)
     simplecov-html (0.10.0)
-    term-ansicolor (1.3.2)
-      tins (~> 1.0)
-    thor (0.19.1)
-    tins (1.6.0)
+    url (0.3.2)
 
 PLATFORMS
   ruby
 
 DEPENDENCIES
-  coveralls (= 0.8.14)
+  codecov
   minitest (~> 5.3)
   mocha (~> 1.1)
   rake (~> 10.3)