This project support for:
- testing private, protected, package access and public method
- testing script performance
https://youngmonkeys.org/projects/test-utilities
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);
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
<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>
testImplementation 'com.tvd12:test-util:1.1.7'
http://www.javadoc.io/doc/com.tvd12/test-util
mvn test
- Touch us on Facebook
- Ask us on stackask.com
- Email to me Dzung
- Apache License, Version 2.0