Skip to content

Instantly share code, notes, and snippets.

@e2kaneko
Created September 25, 2012 10:53
Show Gist options
  • Save e2kaneko/3781146 to your computer and use it in GitHub Desktop.
Save e2kaneko/3781146 to your computer and use it in GitHub Desktop.
SpringFramework TestCase(Sample)
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