| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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<Mutation, MyTestCase> mutationMyTestCaseHashMap = new HashMap<>();
- /**
- * 所有的变异体信息
- */
- public static LinkedHashSet<Mutation> allMutationInfo = new LinkedHashSet<>();
- /**
- * 已经存储在约简库中的测试用例
- */
- static HashSet<MyTestCase> existTestCase = new HashSet<>();
- /**
- * 已经存储在约简库中的测试用例
- */
- static List<MyTestCase> allTestCases = new ArrayList<>();
- public static void mutationDecrease(String path) {
- ExecutorService executorService = MyThreadPool.getThreadpoolInstance();
- List<Future<List<Mutation>>> futures = new ArrayList<>();
- File projectFile = new File(path);
- int count =0;
- for (File file : projectFile.listFiles(File::isDirectory)) {
- // if (count++ == 30)break;
- Future<List<Mutation>> future = executorService.submit(()-> PITestUtil.runAndParsePITest(file.getAbsolutePath()));
- futures.add(future);
- }
- for (Future<List<Mutation>> future : futures) {
- List<Mutation> 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) {
- }
- }
|