package com.frk.mycode; import com.atlassian.clover.registry.entities.TestCaseInfo; import com.frk.mycode.branch.MyBranchInfo; import com.frk.mycode.mutation.Mutation; import com.frk.mycode.mutation.MyTestCase; import java.io.File; import java.util.*; import java.util.concurrent.*; /** * @date 2024/5/17 */ public class PITesrDecrease { /** * 被覆盖的分支-对应的覆盖该分支的测试用例 */ static HashMap mutationMyTestCaseHashMap = new HashMap<>(); /** * 所有的变异体信息 */ public static LinkedHashSet allMutationInfo = new LinkedHashSet<>(); /** * 已经存储在约简库中的测试用例 */ static HashSet existTestCase = new HashSet<>(); /** * 已经存储在约简库中的测试用例 */ static List allTestCases = new ArrayList<>(); public static void mutationDecrease(String path) { ExecutorService executorService = MyThreadPool.getThreadpoolInstance(); List>> futures = new ArrayList<>(); File projectFile = new File(path); int count =0; for (File file : projectFile.listFiles(File::isDirectory)) { // if (count++ == 30)break; Future> future = executorService.submit(()-> PITestUtil.runAndParsePITest(file.getAbsolutePath())); futures.add(future); } for (Future> future : futures) { List mutationList = null; try { mutationList = future.get(60, TimeUnit.SECONDS); if (mutationList == null) continue; allMutationInfo.addAll(mutationList); for (Mutation mutation : mutationList) { if (mutationMyTestCaseHashMap.get(mutation) == null) { if (!mutation.getKilledByTestCases().isEmpty()) { mutationMyTestCaseHashMap.put(mutation, mutation.getKilledByTestCases().get(0)); existTestCase.add(mutation.getKilledByTestCases().get(0)); } } } } catch (InterruptedException | ExecutionException | TimeoutException e) { future.cancel(true); e.printStackTrace(); } } System.out.println("TotalMutation: " + allMutationInfo.size()); System.out.println(allMutationInfo); System.out.println("Killed Mutation: " + mutationMyTestCaseHashMap.size()); System.out.println("TotalTestCse: " + allTestCases.size()); System.out.println(allTestCases); System.out.println("existTestCases: " + existTestCase.size()); System.out.println("Mutation Killed Percent: " + mutationMyTestCaseHashMap.size()*100.0 / allMutationInfo.size()); System.out.println("Decrease Ratio: " + ((allTestCases.size() - existTestCase.size()*1.0) / allTestCases.size())*100.0); System.out.println(mutationMyTestCaseHashMap); } public static void main(String[] args) { } }