||Wireless sensor networks (WSNs) are widely used distributed systems that sense and interact with the physical world. Like other applications, wireless sensor network applications can be plagued by a variety of software faults. These faults can be critical and costly in the debugging and deployment of sensor networks. Furthermore, they are difficult to locate. Therefore, automatic fault localization before deployment can significantly reduce the cost of debugging and deployment of a sensor network system. In general, debugging comprises five steps: finding failure-triggering test cases, simplification of failed test cases, fault localization, repairing and regression testing. In another dimension, faults can reside in application logic, driver of on-board device and networking. Among these dimensions, fault localization has been considered the most important step of debugging, and application logic is more complex and bug-prone. We therefore focus on the study of fault localization of the application logic faults. In this thesis, first, an overview of the thesis is presented. Then, WSN applications and automatic fault localization techniques are introduced. Following that, based on the state-of-the-art fault localization technique Tarantula, the Sensor Network Adapted Tarantula technique (SNAT) has been proposed in order to increase the effectiveness. We also evaluate SNAT by conducting single-mutation-fault controlled experiments. As a result, the effectiveness of Tarantula to locate query-related software faults on wireless sensor networks has been improved. Based on this algorithm, we have also built an infrastructure for before-deployment fault localization on sensor network programs. This infrastructure provides various functions for different WSN debugging tasks performed by both developers and researchers.