0
I am participating in a selection process, and one of the criteria is to implement any kind of unit test, I just wonder if it is implemented right the code below, it is working perfectly, I just need to know if it is implemented right.
@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource("classpath:application.properties")
@ContextConfiguration(classes = { AppConfig.class })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TesteApplicationTests {
@Autowired
private PessoaRepository pessoaRepository;
@Autowired
private PessoaService pessoaService;
@Test
public void testPessoa1Inclusao() throws Exception {
Pessoa pessoa1 = new Pessoa("Marcelo Dultra", "840.622.210-71");
this.pessoaService.salvar(pessoa1);
// Assertions.assertThat(pessoa1.getName()).isNotNull();
}
@Test
public void testPessoa2Exclusao() throws Exception {
Pessoa pessoa = pessoaRepository.findOne((long) 3);
pessoaRepository.delete(pessoa);
}
@Test
public void testPessoa3ExclusaoDaUltima() throws Exception {
List<Pessoa> todasPessoas = pessoaRepository.findAll();
Pessoa ultima = todasPessoas.get(todasPessoas.size() - 1);
pessoaRepository.delete(ultima);
}
@Test
public void testPessoa4Atualizacao() throws Exception {
Pessoa pessoa3 = new Pessoa("Ricardo Falcão1", "213.535.690-55");
this.pessoaService.atualizar(pessoa3.getCodigo().valueOf(4), pessoa3);
}
}
How do we know? We don’t know the requirements. We don’t know the problem deeply. Testing is understanding the problem. Looking at the code from above it seems that not even the actual code seems to be right (without seeing it). When there is something conceptually wrong, what is the point of testing? And even looking only at the tests, they’re naive, trying to see if you do something in a specific situation too much, which is always going to work. Testing is much more complicated and almost everyone does it just to feel good and be fashionable, not to make the application really robust, so it’s a waste of time.
– Maniero
Cool I do not agree, assuming that one of the best companies in Brazil requested unit testing as part of the selection process, if companies request it is because it is important, but this is not a discussion forum, I would be very happy if you could give a more friendly response.
– wladyband
Cool, there’s a guy who calls himself an algorithm teacher, and he said that my tests are wrong, because unit tests are not to effect CRUD in the bank, as I have little experience do not know whether he is wrong. Are these unit tests I’ve done really wrong?
– wladyband
I made a friendly comment, but you are asking to hear what you want, this I do not do because this is deception, as you were deceived by " one of the best companies in Brazil requested the unit tests as part of the selection process". And "a guy who calls himself an algorithm teacher" that’s a wonder of credentials. But he’s right, only it’s not the only problem. I’m sorry I can’t be of more help, and you don’t want the help I can give.
– Maniero
@wladyband really the guy who says he’s a teacher is right. Unit tests are for testing business rules. For example, if the registration is person and has CPF, the system should validate if the CPF/CNPJ is valid, if the date of birth is not greater than 150 years for example. Which are validations that the database itself doesn’t do. I’m not very knowledgeable about testing, but I’ve worked with TDD. Always do fail tests and get it right, that you pass the test if you fail and pass the test if you succeed. More here: https://www.devmedia.com.br/tdd-fundamentos-development-orienteda-testes/28151
– NDelavi