private MutationStatusTestPair handleCoveredMutation( final MutationDetails mutationId, final Mutant mutatedClass, final List<TestUnit> relevantTests) { final MutationStatusTestPair mutationDetected; if (DEBUG) { LOG.fine("" + relevantTests.size() + " relevant test for " + mutatedClass.getDetails().getMethod()); } final Container c = createNewContainer(); final long t0 = System.currentTimeMillis(); if (this.hotswap.apply(mutationId.getClassName(), this.loader, mutatedClass.getBytes())) { if (DEBUG) { LOG.fine("replaced class with mutant in " + (System.currentTimeMillis() - t0) + " ms"); } mutationDetected = doTestsDetectMutation(c, relevantTests); } else { LOG.warning("Mutation " + mutationId + " was not viable "); mutationDetected = MutationStatusTestPair.notAnalysed(0, DetectionStatus.NON_VIABLE); } return mutationDetected; }
@Test public void shouldReportWhenMutationNotDetected() throws IOException { final MutationDetails mutantOne = makeMutant("foo", 1); final Collection<MutationDetails> range = Arrays.asList(mutantOne); final TestUnit tu = makePassingTest(); when(this.testSource.translateTests(any(List.class))).thenReturn( Collections.singletonList(tu)); when( this.hotswapper.apply(any(ClassName.class), any(ClassLoader.class), any(byte[].class))).thenReturn(true); this.testee.run(range, this.reporter, this.testSource); verify(this.reporter).report(mutantOne.getId(), new MutationStatusTestPair(1, DetectionStatus.SURVIVED, new ArrayList<>(), new ArrayList<>())); }
@Test public void shouldReportWhenMutationNotViable() throws IOException { final MutationDetails mutantOne = makeMutant("foo", 1); final Collection<MutationDetails> range = Arrays.asList(mutantOne); final TestUnit tu = makePassingTest(); when(this.testSource.translateTests(any(List.class))).thenReturn( Collections.singletonList(tu)); when( this.hotswapper.apply(any(ClassName.class), any(ClassLoader.class), any(byte[].class))).thenReturn(false); this.testee.run(range, this.reporter, this.testSource); verify(this.reporter).report(mutantOne.getId(), MutationStatusTestPair.notAnalysed(0, DetectionStatus.NON_VIABLE)); }
@Test public void shouldReportWhenMutationKilledByTest() throws IOException { final MutationDetails mutantOne = makeMutant("foo", 1); final Collection<MutationDetails> range = Arrays.asList(mutantOne); final TestUnit tu = makeFailingTest(); when(this.testSource.translateTests(any(List.class))).thenReturn( Collections.singletonList(tu)); when( this.hotswapper.apply(any(ClassName.class), any(ClassLoader.class), any(byte[].class))).thenReturn(true); this.testee.run(range, this.reporter, this.testSource); verify(this.reporter).report( mutantOne.getId(), new MutationStatusTestPair(1, DetectionStatus.KILLED, tu .getDescription().getName())); }
private MutationStatusTestPair handleCoveredMutation( final MutationDetails mutationId, final Mutant mutatedClass, final List<TestUnit> relevantTests) { final MutationStatusTestPair mutationDetected; if (DEBUG) { LOG.fine("" + relevantTests.size() + " relevant test for " + mutatedClass.getDetails().getMethod()); } final Container c = createNewContainer(); final long t0 = System.currentTimeMillis(); if (this.hotswap.apply(mutationId.getClassName(), this.loader, mutatedClass.getBytes())) { if (DEBUG) { LOG.fine("replaced class with mutant in " + (System.currentTimeMillis() - t0) + " ms"); } mutationDetected = doTestsDetectMutation(c, relevantTests); } else { LOG.warning("Mutation " + mutationId + " was not viable "); mutationDetected = MutationStatusTestPair.notAnalysed(0, DetectionStatus.NON_VIABLE); } return mutationDetected; }