jeudi 4 février 2021

@Service Spring Unit Test too slow

I need to test my Spring Boot app, and I started with the Service testing. But my test seems to take too long, I'm new at this, maybe is not too slow. Can anyone give me some advice, please?

Here is my test:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ProiectLicentaApplication.class)
@AutoConfigureTestDatabase
@Transactional
public class TestJUnit {

    @Autowired
    private UserService userService;
    @Test
    public void testSaveUser(){
   
        User saveToDb = new User("test@gmail.com","test","employee");

        User saved = userService.save(saveToDb);
        Assert.assertEquals(saveToDb.getEmail(),saved.getEmail());
       
    }
}

This simple test takes 230-245 ms. The save method has Spring PasswordEncoder that encodes the password, but I don't think this should slow it that much.

Service method

public User save(User user) {

    String password = passwordEncoder.encode(user.getPassword());
    user.setPassword(password);

   return userRepository.save(user);
}

Aucun commentaire:

Enregistrer un commentaire