Fog computing is an emerging computing paradigm that employs edge devices, machines within the core network, and the cloud. Distributing IoT data via fog-based pub/sub systems has many advantages, including low latency communication between physically close clients, better availability, and reduced bandwidth consumption in the wide-area network. For building, testing, and evaluating such fog-based pub/sub systems, we identified two main needs: First, the need for considering the unique characteristics of the fog and the IoT. Second, the need for automated execution of fog application experiments in a controllable environment. In this thesis, we present three main contributions to address these needs: Our first contribution is BCGroups, an inter-broker routing strategy for distributing IoT data within fog-based pub/sub systems. BCGroups can be used with existing cloud-based pub/sub offers. For routing messages between brokers fast and efficiently, BCGroups uses IoT-specific domain knowledge: low communication latency is often only required between devices in physical proximity. Our second contribution comprises GeoBroker & DisGB, two pub/sub broker systems that leverage geo-context for IoT data distribution. In many IoT scenarios, geo-context information is readily available, i.e., publishers often know where their data is relevant, and subscribers can often specify where relevant data originates. When running on a single machine, GeoBroker reduces the load on the broker system, bandwidth consumption, and the number of irrelevant messages that subscribers need to process. DisGB builds upon GeoBroker and also comprises two novel strategies for inter-broker message routing in multi-machine setups. Both strategies achieve a similar communication latency as flooding events or subscriptions while requiring significantly less inter-broker messages. Our third contribution is MockFog, an approach for the automated execution of fog application experiments in the cloud. The main idea is to use an emulated infrastructure testbed that can be manipulated based on a predefined orchestration schedule. This way, fog applications and fog systems can run in the cloud while experiencing comparable performance and failure characteristics as in a real fog deployment. Moreover, it allows application engineers to test arbitrary failure scenarios and various infrastructure options at large scale.