Created
May 5, 2019 03:40
-
-
Save MichaelZhou111/a4d687228232a1037ea639e24bdf6c83 to your computer and use it in GitHub Desktop.
SpringockitoDemo using testNg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a demo for using springockito