Created
September 25, 2012 10:53
-
-
Save e2kaneko/3781146 to your computer and use it in GitHub Desktop.
SpringFramework TestCase(Sample)
This file contains hidden or 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
package com.e2info.developer.springmvcsample.controller; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
import org.springframework.ui.ModelMap; | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration({ | |
"file:src/main/resources/com/e2info/developer/springmvcsample/util/util-beans.xml", | |
"file:WebContent/WEB-INF/web-servlet.xml" | |
}) | |
public class HelloWorldControllerTest { | |
@Autowired | |
private HelloWorldController helloWorldController; | |
@Test | |
public void testHelloController() { | |
ModelMap model = new ModelMap(); | |
Assert.assertEquals("hello", helloWorldController.printWelcome(model)); | |
Assert.assertEquals(2, model.size()); | |
Assert.assertTrue(model.containsAttribute("message")); | |
Assert.assertTrue(model.containsAttribute("string")); | |
Assert.assertEquals("Spring 3 MVC Hello World", model.get("message")); | |
Assert.assertEquals("[hello]", model.get("string")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment