Smartphones are increasingly popular each year and have more and better sensors. These sensors are a rich information source for creating context-aware applications. Testing these applications directly in living labs is very expensive since it involves, among other things, setting up a reproduction of the environment where the application or service under test will be executed. This paper proposes the UbikMobile architecture which aims to provide developers with tools to test context-aware services based on smartphones in a simulated environment. The primary goal in UbikMobile is to reduce the faults in the software as much as possible. The main contribution is that a real smartphone, and not only an emulator, can be connected to the simulated world to conduct: (1) manual tests (i.e. the developer controls an avatar in the simulation); and, (2) automatic tests (i.e. agents in the simulation are capable of interacting automatically with the smartphone). This paper shows the main design decisions in the architecture presented to allow the interested reader to reproduce or to extend our results. It Also includes a number of case studies to illustrate how to use the architecture.