@RunWith(MockitoJUnitRunner.class) //Class cannot be resolved to a type //@SpringBootTest public class MbankingApplicationTest {
@Mock CanmbTransactionDao dataServiceMock;
@Mock CanmbBaseDao baseDao;
@InjectMocks CanmbTransactionServiceImpl businessImpl;
@Autowired OminiController controller;
Customer customer;
@Test public void test() {
Customer cust= new Customer();
cust.setMbnumber("+919990176197");
cust.setDeviceid("abcdef");
UserProfileMaster profile = new UserProfileMaster();
profile.setChkflag(22);
profile.setStatus("ACTIVE");
cust.setUserProfile(profile);
cust.setMpin("123456");
cust.setMpinsalt("12345");
when(dataServiceMock.getUserMbAndDevice("+919990176197", "abcdef")).thenReturn(cust);
this.customer = cust;
assertEquals(cust, businessImpl.getUserMbAndDevice("+919990176197", "abcdef"));
}
@Test public void testMpin() {
Customer cust = new Customer();
cust.setMbnumber("+919990176197");
cust.setDeviceid("abcdef");
UserProfileMaster profile = new UserProfileMaster(); profile.setChkflag(22);
profile.setStatus("ACTIVE");
cust.setUserProfile(profile);
cust.setMpin("d150cb2c64171a95eb3fa1bbf2ea786aef16b04d389a1ac67a52c75e95f61e66");
cust.setMpinsalt("12345");
when(dataServiceMock.getUserMbAndDevice("+919990176197", "abcdef")).thenReturn(cust);
//assertEquals(cust, businessImpl.getUserMbAndDevice("+919990176197", "abcdef"));
MBSOMNIIntegration reqData = new MBSOMNIIntegration();
reqData.setMbnumber("+919990176197");
reqData.setDeviceid("abcdef");
reqData.setMpin("123456");
OMNIIntegration omni=new OMNIIntegration();
// businessImpl.validateOmniMpin(reqData, omni, "123");
ResponseData data= new ResponseData();
Map<String,String> ominiMap= new HashMap<>();
ominiMap.put("Msg", "verified"); ominiMap.put("statusCode", "0");
data.setStatusCode(0);
data.setTid("");
data.setData(ominiMap);
when(businessImpl.validateOmniMpin(reqData, omni, "123")).thenReturn(data);
assertEquals(data,businessImpl.validateOmniMpin(reqData, omni, "123"));
}
运行测试:2,失败:1,错误:0,跳过:0,经过的时间:0.835秒
<<<失败! -in com.npst.mb.MbankingApplicationTest testMpin(com.npst.mb.MbankingApplicationTest)耗时:0.823秒
<<<失败! java.lang.AssertionError:预期:com.npst.mb.pojo.ResponseData,但在org.junit.Assert.fail(Assert.java:89)上的com.npst.mb.pojo.ResponseData位于org.junit.Assert .failNotEquals(Assert.java:835)在org.junit.Assert.assertEquals(Assert.java:120)在org.junit.Assert.assertEquals(Assert.java:146)在com.npst.mb.MbankingApplicationTest.testMpin( MbankingApplicationTest.java:93)
结果:
失败的测试:MbankingApplicationTest.testMpin:93预期:com.npst.mb.pojo.ResponseData,但是是:com.npst.mb.pojo.ResponseData
运行测试:2,失败:1,错误:0,跳过:0
[INFO] -------------------------------------------------- ---------------------- [INFO]内置失败[INFO] -------------------------------------------------- ---------------------- [INFO]总时间:12.493 s [INFO]完成于:2019-01-17T14:57:43 + 05:30 [ INFO]最终内存:36M / 346M [INFO] -------------------------------------------------- ---------------------- [错误]无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test(默认-test)在项目CapexMbankingPhase2上:存在测试失败。 [错误] [错误]有关各个测试结果,请参阅/ home / npstx / raj / Canara Projects / MBS_APP_OMNI / target / surefire-reports。 [错误]-> [帮助1] [错误] [错误]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。 [错误]使用-X开关重新运行Maven以启用完整的调试日志记录。 [ERROR] [ERROR]有关错误和可能的解决方案的更多信息,请阅读以下文章:[ERROR] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException