zoukankan      html  css  js  c++  java
  • 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的就好的。

  • 相关阅读:
    迁移学习
    GAN
    PCA
    LSTM
    hdu 1754 I Hate It 线段树
    hdu 4292 Food 最大流
    hdu 2222 Keywords Search AC自动机
    hdu 3572 Task Schedule hdu 2883 kebab 最大流
    poj 1966 Cable TV Network 点连通度
    hdu 2236 匹配
  • 原文地址:https://www.cnblogs.com/juepei/p/4134421.html
Copyright © 2011-2022 走看看