This paper introduces a novel framework for hypothesis testing in the presence of unknown parameters. The objective is to decide between two hypotheses, where each one involves unknown parameters that are of interest to be estimated. The existing approaches on detection and estimation place the primary emphasis on the detection part by solving this part optimally and treating the estimation part suboptimally. The proposed framework, in contrast, treats both problems simultaneously and in a jointly optimal manner. The resulting test exhibits the flexibility to strike any desired balance between the detection and estimation accuracies. By exploiting this flexibility, depending on the application in hand, this new technique offers the freedom to put different emphasis on the detection and estimation subproblems. The proposed optimal joint detection and estimation framework is also extended to multiple hypothesis tests. We apply the proposed test to the problem of detecting and estimating periodicities in DNA sequences and demonstrate the advantages of the new framework compared to the classical Neyman-Pearson approach and the GLRT.