mardi 29 septembre 2015

Junit tests for JPA Repository methods

I have the following test method:

@Injected
private ProductRepository productRepository;
    @Test
    @Transactional
    public void shoudChangeProductTilte(){
    Product product = productRepository.getProductById(123L);
            product.setTitle("test_product");
            productRepository.save(product);
            Product updatedProduct = productRepository.getProductById(123L);
    assertNotNull(updatedProduct);
            assertEquals("test_product", updatedProduct.getTitle());
    }

My question is: Do you see any sence in this test? Is it looking good?

All method will be executed it one transaction. I am not sure that we will write anything directly to db. Also, I do not like idea with product and updatedProduct ... hmm, I feel that something wrong, but is it really true?

What do you think?

Aucun commentaire:

Enregistrer un commentaire