Your answer is actually correct, the integral is actually equal to one:
$$ \int_0^1 1 dz = [z]_0^1 = 1 - 0 = 1. $$
Note that if you make the domain larger in the $z$-direction, you will have the proper integral as well :
$$ \int_0^{10} 2 dz = [2z]_0^{10} = 2 \cdot 10 - 0 = 20, $$
as demonstrated in the code snippet below:
from dolfin import *
mesh = BoxMesh(0, 0, 0, 1, 1, 20, 10, 10, 10)
ff = FacetFunction("size_t", mesh, 0)
# calculate boundaries :
for f in facets(mesh):
n = f.normal()
tol = 1e-3
# surface :
if n.z() >= tol and f.exterior():
ff[f] = 1
# base :
elif n.z() <= -tol and f.exterior():
ff[f] = 2
# define function space :
Q = FunctionSpace(mesh, "CG", 1)
def vert_integrate(u, ff, Q):
phi = TestFunction(Q)
v = TrialFunction(Q)
bc = DirichletBC(Q, 0, ff, 2)
a = v.dx(2) * phi * dx
L = u * phi * dx
v = Function(Q)
solve(a == L, v, bc)
return v
# plot solution :
plot(vert_integrate(Constant(2), ff, Q))
interactive()