Intellig IDEA运行单元测试更多次

时间:2020-04-16 10:34:18

标签: java maven unit-testing intellij-idea

我写了这个Util类:

public class FaxFileUtil {
    private static final Log logger = Log.getLog(FaxFileUtil.class);
    private static final String ROOT_FAXES_FOLDER = "faxes/";

    public static File createTempFaxFile(byte[] document, String documentName) throws FaxException {
        logger.info("start creation temp fax file: " + ROOT_FAXES_FOLDER + documentName);
        try {
            File faxAsFile = createFile(documentName);
            logger.info("temp fax file: " + ROOT_FAXES_FOLDER + documentName + " was created successfully");
            FileUtils.writeByteArrayToFile(faxAsFile, document);
            logger.info("fax document was saved to" + ROOT_FAXES_FOLDER + documentName + " successfully");
            return faxAsFile;
        } catch (Exception e) {
            logger.info("during fax document saving to temp fax file: " + ROOT_FAXES_FOLDER + documentName + "was thrown exception: " + e.getMessage());
            throw new FaxException(e);
        }
    }

    private static File createFile(String documentName) throws Exception {
        File file = new File(ROOT_FAXES_FOLDER + documentName);

        if (file.exists())
            throw new Exception("temp fax file: " + ROOT_FAXES_FOLDER + documentName + " already exist");

        return file;
    }

    public static void clearTempFaxFile(String documentName) {
        File file = new File(ROOT_FAXES_FOLDER + documentName);
        if (file.delete()) {
            logger.info(ROOT_FAXES_FOLDER + documentName + " was deleted successfully");
        } else {
            logger.info(ROOT_FAXES_FOLDER + documentName + " was not deleted");
        }
    }
}

我为此课程写了一个单元测试:

public class FaxFileUtilTest {

    @Test
    public void createFile() throws FaxException {
       FaxFileUtil.createTempFaxFile("test1".getBytes(), "testDocumentName1");
    }
}

我删除了传真文件夹并进行了测试。我有一个例外:

Caused by: java.lang.Exception: temp fax file: faxes/testDocumentName1 already exist
    at ...FaxFileUtilTest.createFile(FaxFileUtilTest.java:13)

我跑了一次测试。发生什么事了?

IDEA也运行其他测试。我不懂为什么。我有这个选择:

enter image description here

但是我总是选中此选项。 IDEA将所有调用委托给Maven。

UPD:如果我删除此选项-测试工作正常

0 个答案:

没有答案