Skip to content

Instantly share code, notes, and snippets.

@MichaelZhou111
Created May 5, 2019 03:40
Show Gist options
  • Save MichaelZhou111/a4d687228232a1037ea639e24bdf6c83 to your computer and use it in GitHub Desktop.
Save MichaelZhou111/a4d687228232a1037ea639e24bdf6c83 to your computer and use it in GitHub Desktop.
SpringockitoDemo using testNg
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath:new_resource/spring-config-Michael.xml"})
@Slf4j
@Test
@Service
public class SpringockitoDemo extends AbstractTestNGSpringContextTests {Mo
/**
* this is the unit under test
*/
@Autowired
UnitUnderTest unitUnderTest;
@ReplaceWithMock
@Resource
private DependencyRpc dependencyRpc;
@Test(groups = {"useMock", "P0", "puzzle"},
expectedExceptions = ValidateException.class,
expectedExceptionsMessageRegExp = ".*需要验证的出现在异常中的字符信息.*")
public void 测试意图_冒烟测试() {
InputObject inputObject = TestUtils.getDataByFileName("xxx/basic.json");
Product mockProduct = JSON.parseObject(MockData.mockProductStr,Product.class);
ProductExt mockProductExt = JSON.parseObject(MockData.mockProuctExtStr,ProductExt.class);
try {
when(dependencyRpc.getProductByProductId(anyLong(), anyInt())).thenReturn(mockProduct);
when(dependencyRpc.getProductExtByProductId(anyLong(), anyInt())).thenReturn(mockProductExt);
} catch (JdItemException e) {
log.error("never should be here");
Assert.assertTrue(false);
e.printStackTrace();
}
unitUnderTest.process(inputObject);
}
}
@MichaelZhou111
Copy link
Author

this is a demo for using springockito

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment