• Junit 测试


    看了许多文章,都有说junit的重要性。个人不喜欢用这个,因为我还是比较喜欢写main方法的,虽然麻烦点,但是是个习惯。现在也写写这个,毕竟是很有用的。

    代码拿一下写框架时候的用的吧,代码来自园中的某位大婶。

    import com.tear.ioc.bean.xml.document.XmlDocumentHolder;
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Element;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertNotNull;
    
    public class XmlDocumentHolderTest {
        private XmlDocumentHolder xmlHolder;
        @Before
        public void setUp() throws Exception {
            xmlHolder = new XmlDocumentHolder();
        }
    
        @After
        public void tearDown() throws Exception {
            xmlHolder = null;
        }
    
        @Test
        public void testGetDocument1() {
            String filePath = "test/resources/document/xmlDocumentHolder.xml";
            Document doc1 = xmlHolder.getDocument(filePath);
            assertNotNull(doc1);
            Element root = doc1.getRootElement();
            assertEquals(root.getName(), "beans");
            Document doc2 = xmlHolder.getDocument(filePath);
            System.out.println(doc1);
            System.out.println(doc1);
            assertEquals(doc1, doc2);
        }
    
        @Test(expected = DocumentException.class)
        public void testGetDocument2(){
            String filePath = "test/resources/document/xmlDocumentHolder2.xml";
            Document doc = xmlHolder.getDocument(filePath);
        }
    
        @Test(expected = DocumentException.class)
        public void testGetDocument3() throws DocumentException{
            String filePath = "test/resources/document/xmlDocumentHolder3.xml";
            Document doc = xmlHolder.getDocument(filePath);
        }
    }

    这里少了assertTrue和aseertFalse。引入的包是4的就好的。

  • 相关阅读:
    判断是否是唯一索引异常
    Sign in with Apple java
    spring 集成钉钉机器人
    list一个字段去重
    Math_Linear_algebra_05_正定矩阵
    Math_Linear_algebra_02_矩阵与线性方程
    Math_Calculus_04_多变量微积分
    Math_Linear_algebra_01_向量空间
    Linux_Best Practice_04_Ubuntu 18.04
    PMP_Previw
  • 原文地址:https://www.cnblogs.com/juepei/p/4134421.html
Copyright © 2020-2023  润新知