Spring JUnit Unit Test Cases

Source: Internet
Author: User
Tags json
overall structure of the project

Create a JUnit Testcase

Create a new JUnit TestCase class under the Test/java package directory, as follows:

Applyrequestspeedv3test.java

Package com.yirendai.borrowbase.node.applyrequest.yrd.fast3;
Import Com.yirendai.borrowbase.api.ServiceResult;
Import Com.yirendai.borrowbase.api.applyrequest.IApplyRequestSpeedV3Facade;
Import Com.yirendai.borrowbase.api.applyrequest.model.ApplyRequestSpeedV3Query;
Import Com.yirendai.borrowbase.api.applyrequest.model.ResultApplyRequestVO;
Import Com.yirendai.borrowbase.api.applyrequest.model.common.SpeedV3TransportInVO;
Import Com.yirendai.borrowbase.node.test.util.ParamUtil;
Import Org.junit.Before;
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 java.io.IOException; /** * * @author Ricky Fung * @create 2016-07-08 10:28 * * @RunWith (Springjunit4classrunner.class) @ContextConfiguration (locations = {"Classpath:applicationContext.xml"}) public class applyrequestspeedv3tEST {@Autowired private iapplyrequestspeedv3facade applyrequestspeedv3facade;

    Private String Basedir = "/data/applyrequest/speed3";

    Private applyrequestspeedv3query query; @Before public void Init () throws IOException {Speedv3transportinvo transportinvo = Paramutil.readjsonfile (b

        Asedir, "Apply_request_info.json", Speedv3transportinvo.class); query = applyrequestspeedv3query. Custom (). Setclientidentify ("the"). Setp
                Latformcode ("YrdAs3"). Setsystemmodel ("Coolpad 8730L"). Setsystemphone ("Android 4.3")
    . Settransportinvo (TRANSPORTINVO). build (); } @Test public void Testapplyrequest () {serviceresult<resultapplyrequestvo> result = Applyrequests
        Peedv3facade.applyrequest (query);

    SYSTEM.OUT.PRINTLN ("Preliminary examination results:" +result);
 }

}

Paramutil.java

Package com.yirendai.borrowbase.node.test.util;

Import Com.alibaba.fastjson.JSON;
Import Com.google.common.io.Files;

Import Java.io.File;
Import java.io.IOException;
Import Java.nio.charset.Charset;

/**
 * Created by 123 on 2015/12/16.
 *
/public class Paramutil {public

    static <T> T readjsonfile (String file, class<t> clazz)
            Throws IOException {
        String path = Class.class.getResource (file). GetFile ();
        String JSON = files.tostring (new File (path), Charset.defaultcharset ());
        Return Json.parseobject (JSON, clazz);
    }

    public static <T> T readjsonfile (String dir, String fileName, Class<t> clazz) throws IOException {
        return Readjsonfile (dir + '/' + fileName, clazz);
    }

    public static <T> T readxmlfile (String file, class<t> clazz) {
        return null;
    }

}
Test resource File

Create a new/data/applyrequest/speed3 directory under the Test/resources directory, creating a Apply_request_info.json file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.