Git Product home page Git Product logo

test-util's Introduction

Build Status Dependency Status Coverage Status Maven Central Javadocs

Synopsis

This project support for:

  • testing private, protected, package access and public method
  • testing script performance

Documentation

https://youngmonkeys.org/project/test-util

Code Example

1. Test script performance

long time = Performance.create()
	.threadCount(100) // set 0 if you want to run in sync mode
	.loop(1000000000) // optional, default 1000000
	.test(() -> System.out.println("Hello World"))
	.getTime();

2. Assertion

Asserts.assertEquals(expected, actual);

Asserts.assertThat(actual).isEqualsTo(expected);

Asserts.assertThat(future).isEqualsTo(expected);

3. Random

RandomUtil.randomSmallInt();

RandomUtil.randomShortAlphabetString();

RandomUtil.randomMap(size, int.class, String.class);

4. Get method by name

// with no arguments
Method nothing = MethodUtil.getMethod("nothing", ClassA.class);

// with one argument (Integer)
Method add = MethodUtil.getMethod("add", ClassA.class, Integer.class);

5. Invoke method

// invoke method
Integer result = MethodUtil.invokeMethod(add, new ClassA(), new Integer(1));

//invoke method by name
Integer result = MethodUtil.invokeMethod("add", new ClassA(), new Integer(1));

// invoke static method by name
MethodUtil.invokeStaticMethod("hello", ClassA.class, "tvd12.com");

// use builder syntax
Integer result = MethodInvoker.create()
        .method("add")
        .param(new Integer(1))
        .object(new ClassA())
        .invoke(Integer.class);

Motivation

Because sometimes we want to call private, protected, package access and public method, we need test performance to our script and export result to file so, we need create a library to support them

Installation

Maven

<dependency>
	<groupId>com.tvd12</groupId>
	<artifactId>test-util</artifactId>
	<version>1.1.7</version>
</dependency>

You need create file AllTests.tng.xml in your src/test/resources folder with content, example:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All-Test">
    <test name="All">
    	<packages>
    		<package name="your_test_package"/>
    	</packages>
    </test>
</suite>

Gradle

testImplementation 'com.tvd12:test-util:1.1.7'

API Reference

http://www.javadoc.io/doc/com.tvd12/test-util

Tests

mvn test

Contact us

License

  • Apache License, Version 2.0

test-util's People

Contributors

tvd12 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.