Merge lp:~elopio/snapcraft/integration_coverage into lp:~snappy-dev/snapcraft/core

Proposed by Leo Arias
Status: Merged
Approved by: Leo Arias
Approved revision: 96
Merged at revision: 97
Proposed branch: lp:~elopio/snapcraft/integration_coverage
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 187 lines (+73/-15)
3 files modified
bin/snapcraft-coverage (+44/-0)
integration-tests/units/jobs.pxu (+11/-11)
runtests.sh (+18/-4)
To merge this branch: bzr merge lp:~elopio/snapcraft/integration_coverage
Reviewer Review Type Date Requested Status
Michael Terry (community) Needs Information
Michael Vogt (community) Approve
Review via email: mp+265476@code.launchpad.net

Commit message

Added coverage report to the integration tests.

To post a comment you must log in.
95. By Leo Arias

Removed extra newline.

Revision history for this message
Leo Arias (elopio) wrote :

I tried way to many things to get this working. I'm not totally happy with the approach, but it works. If you can think of a better way to do this, please leave a comment.

Revision history for this message
Michael Vogt (mvo) wrote :

Nice approach, I like it!

review: Approve
Revision history for this message
Michael Terry (mterry) wrote :

I'm fine with the approach of a second, coverage-enabled binary. But don't we want to combine the unit tests and integration tests for the coverage report?

review: Needs Information
Revision history for this message
Michael Terry (mterry) wrote :

(that is, have one report, not two)

Revision history for this message
Leo Arias (elopio) wrote :

> I'm fine with the approach of a second, coverage-enabled binary. But don't we
> want to combine the unit tests and integration tests for the coverage report?

I've pushed a small change that combines the two reports.

I don't like this, but for now seems ok to me.

What I would prefer is to do test-driven development. So the unit test coverage should be close to 100%, and the unit coverage report will be just a guide of how well we are doing TDD.
On top of that, I would use the functional tests to cover the happy paths of the user-facing features. Plus some regressions tests or tests for important error conditions. Then the integration coverage report won't be close to 100%, and the simple table is not useful. What's useful is the HTML report that we can use to discover important user-facing features not covered.

There is no correct approach here, so we can discuss and feel free to disagree. If we decide to go the full TDD way, we can split the reports later and display the HTML nicely in the jenkins server.

thanks for the reviews!

96. By Leo Arias

Combine the two coverage reports.

Revision history for this message
Michael Terry (mterry) wrote :

Well, I guess I considered integration tests a part of TDD too. But maybe that's not the Correct way.

You're the testing expert. :) If you would rather see us drive unit tests to 100% separately from integration tests, that's fine and we can split them.

Revision history for this message
Leo Arias (elopio) wrote :

Here's your typical "expert" comment: there's no correct way :)
Lets play with this for now, and try to increase the overall coverage.

Revision history for this message
Michael Vogt (mvo) wrote :

I was assuming we would keep them separate as they are a different kind of testing. But its fine and easy enough to change later so no issue from my side.

Revision history for this message
Leo Arias (elopio) wrote :

approved too soon? sorry about that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/snapcraft-coverage'
2--- bin/snapcraft-coverage 1970-01-01 00:00:00 +0000
3+++ bin/snapcraft-coverage 2015-07-22 14:22:27 +0000
4@@ -0,0 +1,44 @@
5+#!/usr/bin/python3
6+# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
7+#
8+# Copyright (C) 2015 Canonical Ltd
9+#
10+# This program is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU General Public License version 3 as
12+# published by the Free Software Foundation.
13+#
14+# This program is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+# GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License
20+# along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
22+import os
23+import sys
24+
25+import coverage
26+
27+# make running from bzr snapshot easy
28+topdir = os.path.abspath(os.path.join(__file__, "..", ".."))
29+if os.path.exists(os.path.join(topdir, 'setup.py')):
30+ sys.path = [topdir] + sys.path
31+
32+# now import
33+import snapcraft.main
34+import snapcraft.dirs
35+
36+
37+if __name__ == "__main__":
38+ cov = coverage.coverage(
39+ data_file=os.path.join(topdir, '.coverage'), data_suffix=True,
40+ branch=True, source=['snapcraft'])
41+ cov.start()
42+ try:
43+ snapcraft.dirs.setup_dirs()
44+ snapcraft.main.main()
45+ except:
46+ cov.stop()
47+ cov.save()
48+ raise
49
50=== modified file 'integration-tests/units/jobs.pxu'
51--- integration-tests/units/jobs.pxu 2015-07-10 19:21:16 +0000
52+++ integration-tests/units/jobs.pxu 2015-07-22 14:22:27 +0000
53@@ -3,7 +3,7 @@
54 estimated_duration: 0.1
55 command:
56 set -x
57- OUTPUT=$(snapcraft pull)
58+ OUTPUT=$(${SNAPCRAFT} pull)
59 test $? = 1 || exit 1
60 echo $OUTPUT | grep "Could not find snapcraft\.yaml\."
61
62@@ -13,10 +13,10 @@
63 command:
64 set -ex
65 cp -rT $PLAINBOX_PROVIDER_DATA/local-source .
66- snapcraft build
67+ ${SNAPCRAFT} build
68 test -e stamp-all
69 test "$(readlink parts/make-project/build)" = "$(pwd)"
70- snapcraft stage
71+ ${SNAPCRAFT} stage
72 test -e stamp-install
73
74 id: snapcraft/normal/local-plugin
75@@ -25,7 +25,7 @@
76 command:
77 set -ex
78 cp -rT $PLAINBOX_PROVIDER_DATA/local-plugin .
79- snapcraft snap
80+ ${SNAPCRAFT} snap
81 test -e snap/build-stamp
82
83 id: snapcraft/normal/simple-make
84@@ -34,7 +34,7 @@
85 command:
86 set -ex
87 cp -rT $PLAINBOX_PROVIDER_DATA/simple-make .
88- snapcraft snap
89+ ${SNAPCRAFT} snap
90 test "$(./snap/bin/test)" = "Hello world"
91
92 id: snapcraft/normal/simple-cmake
93@@ -43,7 +43,7 @@
94 command:
95 set -ex
96 cp -rT $PLAINBOX_PROVIDER_DATA/simple-cmake .
97- snapcraft snap
98+ ${SNAPCRAFT} snap
99 test "$(./snap/bin/simple-cmake)" = "It's a CMake world"
100
101 id: snapcraft/normal/conflicts
102@@ -52,7 +52,7 @@
103 command:
104 set -x
105 cp -rT $PLAINBOX_PROVIDER_DATA/conflicts .
106- OUTPUT=$(snapcraft stage)
107+ OUTPUT=$(${SNAPCRAFT} stage)
108 test $? = 1 || exit 1
109 echo $OUTPUT | grep "Error: parts p1 and p2 have the following files in common: bin/test" # squished output by bash
110
111@@ -62,10 +62,10 @@
112 command:
113 set -ex
114 cp -rT $PLAINBOX_PROVIDER_DATA/dependencies .
115- snapcraft snap
116+ ${SNAPCRAFT} snap
117 test -x stage/bin/p3
118 test -x snap/bin/p3
119- test "$(snapcraft shell p3)" = 'p1
120+ test "$(${SNAPCRAFT} shell p3)" = 'p1
121 p1
122 p2'
123
124@@ -76,7 +76,7 @@
125 set -x
126 cp -rT $PLAINBOX_PROVIDER_DATA/dependencies .
127 sed -i "s/p1:/p1:\n after: [p3]/" snapcraft.yaml
128- OUTPUT=$(snapcraft pull)
129+ OUTPUT=$(${SNAPCRAFT} pull)
130 test $? = 1 || exit 1
131 echo $OUTPUT | grep -i "circular dependency"
132
133@@ -87,5 +87,5 @@
134 set -x
135 cp -rT $PLAINBOX_PROVIDER_DATA/dependencies .
136 sed -i '/after/d' snapcraft.yaml
137- snapcraft snap
138+ ${SNAPCRAFT} snap
139 test $? = 1 || exit 1
140
141=== modified file 'runtests.sh'
142--- runtests.sh 2015-07-21 02:03:13 +0000
143+++ runtests.sh 2015-07-22 14:22:27 +0000
144@@ -28,11 +28,10 @@
145 pyflakes3 $SRC_PATHS
146
147 if which python3-coverage >/dev/null 2>&1; then
148- python3-coverage erase
149- python3-coverage run --branch --source snapcraft -m unittest
150- python3-coverage report
151+ python3-coverage run --branch --source snapcraft -m unittest
152+ mv .coverage .coverage.unit
153 else
154- python3 -m unittest
155+ python3 -m unittest
156 fi
157
158 if [ -z "$SNAPCRAFT_TESTS_SKIP_PLAINBOX" ]; then
159@@ -49,6 +48,14 @@
160 exit 1
161 fi
162
163+ if which python3-coverage >/dev/null 2>&1; then
164+ python3-coverage erase
165+ export PROJECT_PATH=$(pwd)
166+ export SNAPCRAFT=snapcraft-coverage
167+ else
168+ export SNAPCRAFT=snapcraft
169+ fi
170+
171 # Go to the plainbox provider of snapcraft tests
172 cd integration-tests/
173 # Create a temporary directory so that we can run 'manage.py develop' and
174@@ -77,6 +84,13 @@
175 raise SystemExit(failed)
176 __PYTHON__
177 )
178+
179+fi
180+
181+if which python3-coverage >/dev/null 2>&1; then
182+ python3-coverage combine
183+ python3-coverage report
184+ python3-coverage erase
185 fi
186
187 echo -e "\e[1;32mEverything passed\e[0m"

Subscribers

People subscribed via source and target branches

to all changes: