The space is comming from topsep, so you need to set this to 0 for this environment. The easiest way to this is with \AtBeginEnvironment from the etoolbox package which will keep the change local to the environment:

\documentclass{article}
\usepackage{alltt}
\usepackage{etoolbox}
\AtBeginEnvironment{alltt}{\setlength{\topsep}{0pt}}
\begin{document}
Test1
\begin{alltt}
some code
\end{alltt}
Test2
\end{document}
Putting \showthe\topsep in the file outside the patched environment, gives
> 8.0pt plus 2.0pt minus 4.0pt.
l.14 \showthe\topsep
showing its standard value for this document. This stretchable space was what you were seeing in the original. The alltt environment is built form a trivlist. If you look in the LaTeX source (texdoc source2e on most systems), you will see a description of the vertical spacing parameters for such environments.