testNG


Del ultimo post, hay un test con JUnit.
El mismo test pero con TestNG:

		<!-- en el pom.xml quitar la dependencia con JUnit y añadir-->
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>6.8.5</version>
			<scope>test</scope>
		</dependency>
package net.prietopalacios.josemanuel.aop.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

@ContextConfiguration("file:src/main/resources/spring.xml")
public class ServiceImplTest extends AbstractTestNGSpringContextTests {
	
	@Autowired
	Service service;

	@Test(threadPoolSize = 2, invocationCount = 2,  timeOut = 10000)
//	@Test(threadPoolSize = 2, invocationCount = 4)
	public void testDoSomething() {
		try {
			service.sendSomething();
			assertTrue(true);
		} catch (Exception e) {
			assertException(e);
		}
		
	}
	
	@Test(threadPoolSize = 2, invocationCount = 2,  timeOut = 10000)
	public void testThrowEsception() {
		try {
			service.sendEsception();
			assertTrue(true);
		} catch (Exception e) {
			assertException(e);
		}
	}

	private void assertException(Exception e) {
		if(e.getMessage() != null){
			assertTrue(false, e.getMessage());
		}else{
			assertTrue(false, e.getCause().getMessage());
		}
	}

}
Anuncios
testNG