@Transactional在junit测试后没有做回滚

时间:2016-06-27 12:34:58

标签: spring-boot jersey-test-framework

我正在尝试使用泽西测试框架测试泽西终点。我用@ org.springframework.transaction.annotation.Transactional注释了我的测试类。测试运行正常,但不会回滚。

OfferControllerTest

def get_index_and_value(d, key):
    return d.keys().index(key), d[key]

print(get_index_and_value(d, 'second')

OfferServiceImpl

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(MyApplication.class)
@Transactional
public class OfferControllerTest extends JerseyTest {
@Test
    public void insertOrderTest() {
        Entity<InsertOffersRequest> insertOffersRequestEntity = Entity.entity(insertOffersRequest,
                MediaType.APPLICATION_JSON_TYPE);
        Response response = target(SavioUriConstants.ORDER_INSERT).register(provider)
                .register(HttpAuthenticationFeature.basic(env.getProperty("username"), env.getProperty("password")))
                .request(MediaType.APPLICATION_JSON_TYPE).post(insertOffersRequestEntity);
        assertEquals(200, response.getStatus());
        assertEquals("OFFERS IS ADDED SUCCESSFULLY", response.readEntity(OfferInsertResponse.class).getMessage());
    }

在控制台上

 @Service
    public class OffersServicesImpl  implements OffersService{

public OfferInsertResponse insertOffers(InsertOffersRequest request) {

            log.info("Insert offerInsert Services");
    Offers offers = new Offers();
            offers.setOffImage(request.getImage());
            offers.setOffLogo(request.getLogo());
            offers.setOffCompanyName(request.getCompanyName());
    Offers offer = (Offers) offersRepository.save(offers);

我知道如何回滚测试类插入的行?

1 个答案:

答案 0 :(得分:0)

尝试向测试类添加注释

<select  class="form-control" id="subcategory" name="subcategory" required>
<?php
$categories="SELECT Name,Category FROM SubCategory ORDER BY Category ASC, Name ASC;";
$query_categories=mysqli_query($connh,$categories);
$category_name_old = '';
while($rows_categories=mysqli_fetch_array($query_categories)){

    if($rows_categories['Category'] != $category_name_old) {
        echo "<optgroup label=".$rows_categories['Category'].">";
        echo "<option>".$rows_categories['Name']."</option>";
    }
    else {
        echo "<option>".$rows_categories['Name']."</option>";
    }
    $category_name_old = $rows_categories['Category'];
    if($category != $category_name_old) {
        echo "</optgroup>";
    }
}  
                                                                    } 
?>
</select>

这将指示事务始终回滚。