Я использую Java core 8, и у меня есть один классовый тест с JUnit 4.13.
В методе моего кода оператор "code.hashCode ();" изменить результаты моих тестов.
Я не понимаю, потому что я не переопределил метод hashCode в классе моего объекта кода.
Когда я удаляю эти два оператора, тест "test_generate_properly" не удался, и другой успех.
Мои тесты манипулируют папками, поэтому я знаю, что это может быть побочным эффектом,
Но я не понимаю, почему оператор code.hashCode () меняет результат
Ниже мой единственный класс теста
И класс «Код» (тип переменной «код»).
Спасибо за ваши ответы
Я уже изучаю побочный эффект метода hashCode и многократно запускаю тест класса.
package test.code.generation.v1_2;
import org.junit.Test;
import com.code.generation.v1_2.util.for_test.ICodesComputer;
import com.code.generation.v1_2.util.for_test.organization.BaseTestFolderOrganization;
import com.code.generation.v1_2.util.for_test.results.compiled.ICompiledResult;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
public class CodeBaseTest {
private ICodesComputer codeComputer;
public CodeBaseTest() {
codeComputer = ICodesComputer.instance();
}
@Test
public void test_all_failed_codes_failed() throws IOException {
// use codeComputer for compiling programs in a base of test and
// compare the results
}
@Test
public void test_generate_properly() throws IOException, InterruptedException {
// use codeComputer for compiling programs in a base of test and compare the results
}
}
package com.code.generation.v1_2.elements.scope;
import com.generated.GrammarParser;
public class Code {
private String name;
private GrammarParser.ProgContext progContext;
public Code(String name, GrammarParser.ProgContext progContext) {
this.name = name;
this.progContext = progContext;
}
public String getName() {
return name;
}
public GrammarParser.ProgContext getProgContext() {
return progContext;
}
}