Home > Back-end >  Junit 4 test data to the controller
Junit 4 test data to the controller

Time:09-21

The method of the controller logic of a save data
Junit test in incoming to save data
But will quote mapper null pointer errors

Figure 1 is the method of the controller

Figure 2 is the method of the test class


I need to do to the normal to the test data of written
I don't want to separate mapper written test is want to test a whole process from the incoming data to write back

CodePudding user response:

In junit integration environment of the spring

CodePudding user response:

 
@ RunWith (SpringJUnit4ClassRunner. Class)
@ ContextConfiguration ({" classpath: applicationContext. XML "})
Public abstract class AbstractSpringTest {}

Public class SpringBeanTest extends AbstractSpringTest implements ApplicationContextAware {
Private ApplicationContext ac;
Private MemberLevelService MemberLevelService;

@ Override
Public void setApplicationContext (ApplicationContext arg0) throws BeansException {
This. Ac=arg0;
}

@ Before
Public void before () {
MemberLevelService=ac. GetBean (memberLevelService. Class);
}
@ Test @ Ignore
Public void testMemberLevel () {
Double sc=32;
Result A=memberLevelService. GetMemeberLevel (sc);
If (Anderson sSuccess ()) {
System. The out. Println (" level no: "+ a.s uccessValue (). The getId () +", the title: "+ a.s uccessValue () getNames ());
} else {
System. The out. Println (" level query fail ");
}
}
}


Environmental jdk8, junit 4.12, spring 5.0.7. RELEASE,

Pom. The XML part test depend on the
 

Org. Springframework
Spring - test
${spring - framework. Version} & lt;/version>
Test


Junit
Junit
. ${junit version} & lt;/version>
Test


Org. Springframework
Spring - instrument
${spring - framework. Version} & lt;/version>

CodePudding user response:

Is your mapper and type? If the transformation framework class (fastxml) as long as get registered bean in the spring, and if the test spring MVC controller method with mock framework finally test: do not use on what kind of business reference
  • Related