PITesrDecrease.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.frk.mycode;
  2. import com.atlassian.clover.registry.entities.TestCaseInfo;
  3. import com.frk.mycode.branch.MyBranchInfo;
  4. import com.frk.mycode.mutation.Mutation;
  5. import com.frk.mycode.mutation.MyTestCase;
  6. import java.io.File;
  7. import java.util.*;
  8. import java.util.concurrent.*;
  9. /**
  10. * @date 2024/5/17
  11. */
  12. public class PITesrDecrease {
  13. /**
  14. * 被覆盖的分支-对应的覆盖该分支的测试用例
  15. */
  16. static HashMap<Mutation, MyTestCase> mutationMyTestCaseHashMap = new HashMap<>();
  17. /**
  18. * 所有的变异体信息
  19. */
  20. public static LinkedHashSet<Mutation> allMutationInfo = new LinkedHashSet<>();
  21. /**
  22. * 已经存储在约简库中的测试用例
  23. */
  24. static HashSet<MyTestCase> existTestCase = new HashSet<>();
  25. /**
  26. * 已经存储在约简库中的测试用例
  27. */
  28. static List<MyTestCase> allTestCases = new ArrayList<>();
  29. public static void mutationDecrease(String path) {
  30. ExecutorService executorService = MyThreadPool.getThreadpoolInstance();
  31. List<Future<List<Mutation>>> futures = new ArrayList<>();
  32. File projectFile = new File(path);
  33. int count =0;
  34. for (File file : projectFile.listFiles(File::isDirectory)) {
  35. // if (count++ == 30)break;
  36. Future<List<Mutation>> future = executorService.submit(()-> PITestUtil.runAndParsePITest(file.getAbsolutePath()));
  37. futures.add(future);
  38. }
  39. for (Future<List<Mutation>> future : futures) {
  40. List<Mutation> mutationList = null;
  41. try {
  42. mutationList = future.get(60, TimeUnit.SECONDS);
  43. if (mutationList == null) continue;
  44. allMutationInfo.addAll(mutationList);
  45. for (Mutation mutation : mutationList) {
  46. if (mutationMyTestCaseHashMap.get(mutation) == null) {
  47. if (!mutation.getKilledByTestCases().isEmpty()) {
  48. mutationMyTestCaseHashMap.put(mutation, mutation.getKilledByTestCases().get(0));
  49. existTestCase.add(mutation.getKilledByTestCases().get(0));
  50. }
  51. }
  52. }
  53. } catch (InterruptedException | ExecutionException | TimeoutException e) {
  54. future.cancel(true);
  55. e.printStackTrace();
  56. }
  57. }
  58. System.out.println("TotalMutation: " + allMutationInfo.size());
  59. System.out.println(allMutationInfo);
  60. System.out.println("Killed Mutation: " + mutationMyTestCaseHashMap.size());
  61. System.out.println("TotalTestCse: " + allTestCases.size());
  62. System.out.println(allTestCases);
  63. System.out.println("existTestCases: " + existTestCase.size());
  64. System.out.println("Mutation Killed Percent: " + mutationMyTestCaseHashMap.size()*100.0 / allMutationInfo.size());
  65. System.out.println("Decrease Ratio: " + ((allTestCases.size() - existTestCase.size()*1.0) / allTestCases.size())*100.0);
  66. System.out.println(mutationMyTestCaseHashMap);
  67. }
  68. public static void main(String[] args) {
  69. }
  70. }