SSM framework of integrated system how to do the test?

 

1. First, a new base class test in the test folder BaseTest

BaseTest code as follows:

Package wbl_ssm_blog.mapper; 

Import org.junit.Test;
 Import org.junit.runner.RunWith; 

Import org.slf4j.Logger;
 Import org.slf4j.LoggerFactory;
 Import org.springframework.test.context.ContextConfiguration;
 Import org.springframework .test.context.junit4.SpringJUnit4ClassRunner;
 Import org.springframework.test.context.web.WebAppConfiguration; 



// load test run basic environment JUnit4 
@RunWith (the SpringJUnit4ClassRunner. class )
 // load the resources below all the source code 
@WebAppConfiguration ( " src / main / Resouces " )
 // load mybatis all evil profiles
@ContextConfiguration(locations={"classpath:mybatis/mybatis-config.xml",
        "classpath:spring/spring-mybatis.xml"})
public class BaseTest{
    protected Logger log = LoggerFactory.getLogger(getClass());
    @Test
    public void test(){
        System.out.println("aaa");
    }
}

And then create a test class we actually need to use this test we just need to inherit a new class of BaseTest.

package wbl_ssm_blog.mapper;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import wbl_ssm_blog.entity.Article;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import static org.junit.Assert.*;

public class ArticleMapperTest extends BaseTest{

    @Autowired
    public ArticleMapper articleMapper ;



    @Test
    public void findArticleBySome()
    {
        List<Article> articleList = articleMapper.findArticleBySome("的",10);
        System.out.println(articleList.size());
        for(Article article : articleList)
        {
            System.out.println(article);
        }
    }

    @Test
    public void findArticleBySome01()
    {
        Article criteria = new Article();
        criteria.setArticleTitle("操作");
        criteria.setArticleViewCount(2);
        List<Article> articleList = articleMapper.findArticleBySome01(criteria);
        System.out.println(articleList.size());
        for(Article article : articleList)
        {
            System.out.println(article);
        }
    }

    @Test
    public void deleteById()
    {
        int returnResult = articleMapper.deleteById(36);
        System.out.println (returnResult);
    } 

    @Test 
    public  void INSERT () 
    { 
        Article This article was Article This article was = new new Article This article was (); 
        article.setArticleViewCount ( 10 ); 
        article.setArticleTitle ( "hello, this is the title of the test article" ); 
        article.setArticleCommentCount ( 20 is ); 
        Article This article was. setArticleContent ( "hello, this is the content of the test article" ); 
        article.setArticleCreateTime ( new new a Date ()); 
        article.setArticleUpdateTime ( new new a Date ()); 
        article.setArticleIsComment ( 1); 
        article.setArticleLikeCount ( 20 ); 
        article.setArticleOrder ( 1 ); 
        article.setArticleStatus ( 1 ); 
        article.setArticleSummary ( "Hello, this is a summary of the test article" ); 
        article.setArticleUserId ( 1 ); 

        articleMapper.insert (Article This article was); 
        System.out.println (article.getArticleId ()); 
    } 

    @Test 
    public  void Update () 
    { 
        article This article was article This article was = new new article This article was (); 
        article.setArticleId ( 39 ); 
        article.setArticleTitle ( "Hello, the title of the article 39 updated " );
        article.setArticleContent ( "Hello, the contents of the article 39 is updated" ); 
        article.setArticleSummary ( "Hello summary, article 39 is updated" ); 

        articleMapper.update (Article This article was); 
        System.out.println (Article This article was ); 
    } 

    @Test 
    public  void the findAll () 
    { 
        the HashMap <String, Object> = cateria new new the HashMap <String, Object> (); 
        cateria.put ( "Status",. 1 ); 
        cateria.put ( "the userId",. 1 ) ;
         // cateria.put ( "Keywords", "operation");
         // cateria.put ( "categoryId",. 1);
        cateria.put("tagId",1);
        List<Article> articleList = articleMapper.findAll(cateria);
        System.out.println();
        // order by `article`.`article_order` DESC ,`article`.`article_id` DESC
    }

    @Test
    public void listAllNotWithContent()
    {
        List<Article> articleList = articleMapper.listAllNotWithContent();
        System.out.println();
    }

    @Test
    public void countArticle()
    {
        int rows = articleMapper.countArticle(1);
        System.out.println();
    }

    @Test
    public void countArticleComment()
    {
        int commentCount = articleMapper.countArticleComment();
        System.out.println();
    }

    @Test
    public void countArticleView()
    {
        int viewCount = articleMapper.countArticleView();
        System.out.println();
    }

    @Test
    public void getArticleByStatusAndId()
    {
        Article article = articleMapper.getArticleByStatusAndId(1,1);
        System.out.println();
    }

    @Test
    public void pageArtilce()
    {
        List<Article> articleList = articleMapper.pageArtilce(1,5,10);
        System.out.println();
    }

    @Test
    public void deleteBatch()
    {
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(40);
        ids.add(41);
        articleMapper.deleteBatch(ids);
    }


    @Test
    public void listArticleByViewCount()
    {
        List<Article> articleList = articleMapper.listArticleByViewCount(3);
        System.out.println();
    }

    @Test
    public void getAfterArticle()
    {
        Article article = articleMapper.getAfterArticle(1);
        System.out.println();
    }

    @Test
    public void getPreArticle()
    {
        Article article = articleMapper.getPreArticle(2);
        System.out.println();
    }

    @Test
    public void listRadomArticle()
    {
        List<Article> articleList = articleMapper.listRadomArticle(3);
        System.out.println();
    }

    @Test
    public void listArticleByCommentCount()
    {
        List<Article> articleList = articleMapper.listArticleByCommentCount(3);
        System.out.println();
    }

    @Test
    public void updateCommentCount()
    {
        articleMapper.updateCommentCount(3);
        System.out.println();
    }

    @Test
    public void getLastUpdateArticle()
    {
        Article article = articleMapper.getLastUpdateArticle();
        System.out.println();
    }

    @Test
    public void countArticleByUser()
    {
        int articleCount = articleMapper.countArticleByUser(1);
        System.out.println();
    }

    @Test
    public void findArticleByCategoryId()
    {
        List<Article> articleList = articleMapper.findArticleByCategoryId(1,3);
        System.out.println();
    }

    @Test
    public void findArticleByCategoryIds()
    {
        List<Integer> ids = new ArrayList<>();
        ids.add(1);
        ids.add(2);
        ids.add(3);
        List<Article> articleList = articleMapper.findArticleByCategoryIds(ids,5);
        System.out.println();
    }

    @Test
    public void listArticleByLimit()
    {
        List<Article> articleList = articleMapper.listArticleByLimit(3);
        System.out.println();
    }
}

Then you can test the method of mapper.xml file.

 

Guess you like

Origin www.cnblogs.com/1102whw/p/11410553.html