In th e next version of the junit could you add suport to inject junit test in one junit test class ? this will improve tests and give support to reuse junit test in anothers junit test, avoiding duplicate code..

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

In th e next version of the junit could you add suport to inject junit test in one junit test class ? this will improve tests and give support to reuse junit test in anothers junit test, avoiding duplicate code..

JUnit - User mailing list
In th e next version of the junit could you add suport to inject junit test in one junit test class ? this will improve tests and give support to reuse junit test in anothers junit test, avoiding duplicate code..


@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "/ApplicationContext.xml" } )
@Rollback( value = true )
@Transactional
public class ServiceBusinessTest {

   @Autowired
    private ServiceBusiness serviceBusiness;

  @Autowired
    private AgreementBusinessTest agreementBusiness;


@Test
    public Object saveOrUpdate() {
        ServiceTO serviceTO = ServiceTO.buildServiceTO();
        AgreementTO agreementTO = AgreementBusinessTest.buildAgreementTO();
       
        try {
           serviceTO.setAgreementTO( (AgreementTO) agreementBusiness.saveOrUpdate() );    
     
           serviceTO = serviceBusiness.saveOrUpdate( serviceTO );
        } catch ( ValidationException | CSMBusinessException e ) {
            System.out.println( e.getMessage() );
            throw new AssertionError();
        }
        return serviceTO;
    }
}


@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "/ApplicationContext.xml" } )
@Rollback( value = true )
@Transactional
public class AgreementBusinessTest {

    @Autowired
    private AgreementBusiness agreementBusiness;

   // alot of injections of business
 
    @Test
    public void findAll() {
        try {
            @SuppressWarnings( "unused" )
            List< AgreementTO > agreementTOs = agreementBusiness.findAll();

        } catch ( CSMBusinessException e ) {
            throw new AssertionError();
        }
    }

    @Test
    public Object saveOrUpdate() {
        AgreementTO agreementTO = AgreementTO.buildAgreementTO();

        try {
            // a lot of saving dependencies of agreement
            agreementTO = agreementBusiness.saveOrUpdate( agreementTO );
        } catch ( ValidationException | CSMBusinessException e ) {
            System.out.println( e.getMessage() );
            throw new AssertionError();
        }
        return agreementTO;
    }

}

Thanks.