zoukankan      html  css  js  c++  java
  • 在Spring里进行单元测试Junit

    搭建Spring环境(自行搭建):

    @RunWith注解指定使用springJunit的测试运行器

    @ContextConfiguration注解指定测试用的spring配置文件的位置

    import static org.junit.Assert.*;
    import javax.annotation.Resource;
    import org.junit.After;
    import org.junit.AfterClass;
    import org.junit.Before;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    @RunWith(SpringJUnit4ClassRunner.class) 
    @ContextConfiguration(locations={"classpath:applicationContext.xml"})
    public class test
    {
        @Resource
        RelationEventDao an;
    
        @BeforeClass
        public static void setUpBeforeClass() throws Exception
        {
            System.out.println("setUpBeforeClass");
        }
    
        @AfterClass
        public static void tearDownAfterClass() throws Exception
        {
            System.out.println("tearDownAfterClass");
        }
    
        @Before
        public void setUp() throws Exception
        {
            System.out.println("setUp");
        }
    
        @After
        public void tearDown() throws Exception
        {
            System.out.println("tearDown");
        }
    
     
    
        @Test
        public void testTest()
        {
            
            try
            {
                assertNotNull(an.Event("测试的事件"));
            }
            catch (ZhiWeiException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
    
    }
    

      

  • 相关阅读:
    0019. Remove Nth Node From End of List (M)
    0018. 4Sum (M)
    0278. First Bad Version (E)
    0273. Integer to English Words (H)
    0017. Letter Combinations of a Phone Number (M)
    0016. 3Sum Closest (M)
    0015. 3Sum (M)
    软件测试常见面试题
    如何快速掌握DDT数据驱动测试?
    selenium--三种等待方式
  • 原文地址:https://www.cnblogs.com/byteworld/p/5998162.html
Copyright © 2011-2022 走看看