Git Product home page Git Product logo

ymate-platform-test's Introduction

YMATE-PLATFORM-TEST

Maven Central status LICENSE

为 YMP 框架集成 JUnit 测试开发工具包。

Maven包依赖

<dependency>
    <groupId>net.ymate.platform</groupId>
    <artifactId>ymate-platform-test</artifactId>
    <version>1.0.1</version>
</dependency>

示例代码

示例一:模拟控制器方法请求

@RunWith(YMPJUnit4ClassRunner.class)
@EnableAutoScan
@EnableBeanProxy
@EnableDevMode
public class LoginControllerTest {

    @Inject
    private WebMVC webmvc;

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testLogin() throws Exception {
        MockHttpServletResponse response = MockWebRequestHelper.create(webmvc)
            .post("/login")
            .parameter("uname", "admin")
            .parameter("passwd", DigestUtils.md5Hex("admin"))
            .parameter("format", "json")
            .doFilter();
        Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
        JsonWrapper jsonWrapper = JsonWrapper.fromJson(response.getContentAsString());
        Assert.assertNotNull(jsonWrapper);
        System.out.println(jsonWrapper.getAsJsonObject().toString(true, true));
    }
}

示例二:存储器接口方法调用

@RunWith(YMPJUnit4ClassRunner.class)
@EnableAutoScan
@EnableBeanProxy
@EnableDevMode
public class SystemConfigRepositoryTest {

    @Inject
    private JDBC database;

    @Inject
    private ISystemConfigRepository repository;

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testQuerySystemConfigs() throws Exception {
        SystemConfigBean systemConfigBean = SystemConfigBean.builder()
            .siteId("ymate.net")
            .build();
        IResultSet<SystemConfigVO> systemConfigs = repository.querySystemConfigs(database, systemConfigBean, Page.create());
        Assert.assertNotNull(systemConfigs);
    }
}

示例三: 组合单元测试

@RunWith(YMPJUnit4Suite.class)
@Suite.SuiteClasses({
    LoginControllerTest.class,
    SystemConfigRepositoryTest.class
})
@EnableAutoScan
@EnableBeanProxy
@EnableDevMode
public class ControllersTest {

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }
}

One More Thing

YMP 不仅提供便捷的 Web 及其它 Java 项目的快速开发体验,也将不断提供更多丰富的项目实践经验。

感兴趣的小伙伴儿们可以加入官方 QQ 群:480374360,一起交流学习,帮助 YMP 成长!

如果喜欢 YMP,希望得到你的支持和鼓励!

Donation Code

了解更多有关 YMP 框架的内容,请访问官网:https://ymate.net

ymate-platform-test's People

Contributors

suninformation avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.