'Execute the tearDown metod after all the tests

I want to execute the tearDown metod test after all the tests. Now will be execute after every test. Can someone help me?

public class DMTestoTest extends TestCase {

private List<DecoderManager> listaDM = new ArrayList<DecoderManager>();

@BeforeClass
public void setUp() {
    for (int i = 0; i < Costanti.DIM_T; i++) {
        File destFileDecoding = new File(Costanti.DESTPATH_DECODING_T + i + "-stego.pdf");
        System.out.println(destFileDecoding.toString());
        String fileNameDecoding = destFileDecoding.getName().replace(".pdf", "");
        DecoderManager dm = new DecoderManager(destFileDecoding,
                new File(Costanti.DESTPATH_ENCODING_T + "/" + fileNameDecoding + "-message.txt"));
        listaDM.add(i, dm);
    }
    System.out.println("Lista di decoder manager dopo : " + listaDM.toString());
}

@Test
public void test0() {
    String decodedMsg = null;
    try {
        decodedMsg = this.listaDM.get(0).decode();
        assertTrue(decodedMsg.contains(Costanti.PASSPHRASE));
    } catch (IOException ex) {
        ex.printStackTrace();
        fail();
    }
}   

@AfterClass
public void tearDown() {
    System.out.println("Sto facendo il teardown");
    for (DecoderManager decoderManager : listaDM) {
        File fileStego = decoderManager.getToDecodeFile();
        System.out.println("cancello");
        File fileTesto = decoderManager.getMessageDest();
        fileStego.delete();
        fileTesto.delete();
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source