Discovering the set of closed frequent itemsets is one of the fundamental problems in Data Mining. Recent Constraint Programming (CP) approaches for declarative itemset mining have proven their usefulness and flexibility. We propose a global constraint for mining closed frequent itemsets with a filtering algorithm that enforces domain consistency in polynomial time and space. Moreover, itemset mining techniques have been used in a wide range of applications. Over the last years, software testing, and specially the fault localization task, becomes one of the challenging application domains for data mining. The fault localization task aims to locate automatically bugs in programs. We investigate, for the first time, how the fault localization problem can be reduced to a closed frequent itemset problem. We formalize the problem of fault localization as finding the k best itemsets satisfying a set of constraints modeling the most suspicious statements. We use a CP approach to model and to solve our itemset based fault localization problem. We propose a robust CP model based on our ClosedPattern global constraint.