Skip to content

Commit af3c026

Browse files
committed
autotest: correction on loading array types, status extended
1 parent 475361c commit af3c026

File tree

20 files changed

+683
-82
lines changed

20 files changed

+683
-82
lines changed

LICENSE

+505
Large diffs are not rendered by default.

build.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ forkCount=2C
3636
forkedProcessExitTimeoutInSeconds=60
3737
surefire.parallel.forcedTimeout=0
3838
surefire.parallel.timeout=0
39-
surefire.exitTimeout=300
40-
surefire.timeout=300
39+
surefire.exitTimeout=900
40+
surefire.timeout=900
4141
#parallelOptimized=false
4242
#surefire.shutdown=testset
4343
#surefire.testFailureIgnore=true

tsl2.nano.autotest/readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ AutoTestGenerator(PREFIX: tsl2.functiontest.) started with:
296296
* *filter*: (default: this framework package path) fuzzy class+method filter. NOTE: it's fuzzy finding, means, all 'similar' findings will be included!
297297
* *modifier*: (default: -1) java method mofifier bitfield like *public* (=1) *static* (=8) etc. Please have a look at the java class *java.lang.reflect.Modifier* to see all possibilities
298298
* *filter.unsuccessful*: (default: true): if true, a pre-check is done, calling the test for a failing result. If the test will fail, it will be filtered from the real test.
299+
* *filter.voidreturn*: (default: false) whether to filter methods having a return type of *void*. without an output like the returned result, an expectation can only tested against having a specific exception or not.
299300
* *filter.complextypes*: (default: false) all method parameter types and the result type will be checked, if they are standard data types (provided by jdk) and single value types.(nothing like arrays, collections and maps)
300301
* *filter.failing*: (default:false) whether it is allowed to have a method call , throwing an exception as expected result.
301302
* *filter.nullresults*: (default: false) whether it is allowed to have a method call, returning *null* as result.
@@ -413,6 +414,12 @@ In different environment, there may be problems. We try to solve some of them:
413414
* -> Eclipse Problem. Add the junit library manually to your test classpath
414415
* **java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy**
415416
* -> Did you store you file really in the src/test/java path (perhaps you put it into main?)
417+
* **No Classes were found**
418+
* -> Please set the filter in the manner *".*" + AnyClassToTest.class.getPackage().getName() + ".*"* - so your *AnyClassToTest* is loaded with all imports directly on start
419+
* **I cannot see exception stacktraces**
420+
* -> start your jvm with parameter -XX:-OmitStackTraceInFastThrow
421+
* **AllAutoTests hangs until an timeout**
422+
* use JVisualVM to open the hanging process in FeatureTab **Sampler**. Hit **CPU Samples** and open the callstack tree completely. Perhaps you can see an endless loop in your code under test.
416423

417424
## All Together
418425

tsl2.nano.autotest/src/main/java/de/tsl2/nano/autotest/ValueRandomizer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ static <V> Construction<V> constructWithRandomParameters(Class<V> typeOf, int de
142142
}
143143

144144
private static <T> Constructor<T> getBestConstructor(Class<T> typeOf) {
145+
if (BeanClass.hasDefaultConstructor(typeOf))
146+
return Util.trY( () -> typeOf.getConstructor(new Class[0]));
145147
Constructor<T>[] cs = (Constructor<T>[]) typeOf.getConstructors();
146148
for (int i = 0; i < cs.length; i++) {
147149
if (cs[i].getParameterTypes().length == 1)
@@ -182,7 +184,7 @@ else if (types[j].isInterface())
182184
randomObjects[i+j] = createRandomProxy(types[j], zero, depth);
183185
else {
184186
Class type = types[j].equals(Object.class) ? TypeBean.class : types[j];
185-
randomObjects[i+j] = fillRandom(BeanClass.createInstance(type), zero || respectZero(countPerType, i), depth);
187+
randomObjects[i+j] = fillRandom(constructWithRandomParameters(type, depth).instance, zero || respectZero(countPerType, i), depth);
186188
}
187189
}
188190
}

tsl2.nano.autotest/src/main/java/de/tsl2/nano/autotest/creator/AFunctionCaller.java

+34-11
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ public class AFunctionCaller implements Runnable {
2020
protected int cloneIndex = 0;
2121
protected Construction construction;
2222
protected Method source;
23-
protected transient Status status = NEW;
24-
25-
static final Status NEW = new Status(StatusTyp.NEW, null, null);
26-
static final Status INITIALIZED = new Status(StatusTyp.INITIALIZED, null, null);
27-
static final Status OK = new Status(StatusTyp.OK, null, null);
28-
static final Status NULL_RESULT = new Status(StatusTyp.NULL_RESULT, null, null);
23+
protected transient Status status = Status.NEW;
2924

3025
AFunctionCaller(Method source) {
3126
this(0, source);
@@ -58,7 +53,11 @@ protected String parametersAsString() {
5853
return Arrays.toString(getParameter());
5954
} catch (Exception e) {
6055
status = new Status(StatusTyp.PARAMETER_ERROR, e.toString(), e);
61-
return Arrays.toString(parameter);
56+
try {
57+
return Arrays.toString(parameter);
58+
} catch (Exception e1) {
59+
return "UNRESOLVABLE";
60+
}
6261
}
6362
}
6463

@@ -69,15 +68,15 @@ protected Object[] createStartParameter(Class[] arguments) {
6968
@Override
7069
public void run() {
7170
run(source, getParameter());
72-
status = result != null ? OK : NULL_RESULT;
71+
status = result != null ? Status.OK : Status.NULL_RESULT;
7372
}
7473

7574
protected Object run(Method method, Object... args) {
7675
log(StringUtil.fixString(this.getClass().getSimpleName(), 25) + " invoking " + method.getDeclaringClass().getSimpleName() + "." + method.getName() + " with " + Arrays.toString(args));
7776
final Object instance = getInstance(method);
7877
try {
7978
result = method.invoke(instance, args);
80-
status = OK;
79+
status = Status.OK;
8180
return result;
8281
} catch (Throwable e) {
8382
status = new Status(StatusTyp.EXECUTION_ERROR, e.toString(), e);
@@ -128,13 +127,29 @@ public Construction getConstruction() {
128127
}
129128
}
130129

131-
enum StatusTyp {NEW, PARAMETER_UNDEFINED, PARAMETER_ERROR, INITIALIZED, INSTANCE_ERROR
132-
, NULL_RESULT, EXECUTION_ERROR, OK, TEST_FAILED, TESTED}
130+
enum StatusTyp {
131+
NEW(0), FUNC_WITHOUT_INTPUT(1), FUNC_WITHOUT_OUTPUT(1), FUNC_COMPLEX_INPUT(1)
132+
, PARAMETER_UNDEFINED(-1), PARAMETER_ERROR(-1), INITIALIZED(2), INSTANCE_ERROR(-1)
133+
, NULL_RESULT(1), EXECUTION_ERROR(-1), OK(2), STORE_ERROR(-1), TEST_FAILED(-3), TESTED(4);
134+
int level; //to categorize a state
135+
StatusTyp(int level) {this.level = level;};
136+
}
133137
class Status {
134138
StatusTyp typ;
135139
String msg;
136140
Throwable err;
137141

142+
static final Status NEW = new Status(StatusTyp.NEW);
143+
static final Status INITIALIZED = new Status(StatusTyp.INITIALIZED);
144+
static final Status OK = new Status(StatusTyp.OK);
145+
static final Status NULL_RESULT = new Status(StatusTyp.NULL_RESULT);
146+
static final Status FUNC_WITHOUT_INPUT = new Status(StatusTyp.FUNC_WITHOUT_INTPUT);
147+
static final Status FUNC_COMPLEX_INPUT = new Status(StatusTyp.FUNC_COMPLEX_INPUT);
148+
static final Status FUNC_WITHOUT_OUTPUT = new Status(StatusTyp.FUNC_WITHOUT_OUTPUT);
149+
150+
public Status(StatusTyp typ) {
151+
this(typ, null, null);
152+
}
138153
Status(StatusTyp typ, String msg, Throwable err) {
139154
this.typ = typ;
140155
this.msg = msg;
@@ -143,6 +158,14 @@ class Status {
143158
public boolean in(StatusTyp... types) {
144159
return Util.in(typ, types);
145160
}
161+
162+
public boolean isError() {
163+
return typ.level < 0;
164+
}
165+
166+
public boolean isRefused() {
167+
return typ.level == 1;
168+
}
146169

147170
@Override
148171
public String toString() {

tsl2.nano.autotest/src/main/java/de/tsl2/nano/autotest/creator/AFunctionTester.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ private boolean shouldFail(Throwable error) {
155155
if (getExpectFail() != null) {
156156
if (error == null)
157157
fail("test should fail with " + getExpectFail() + " but has result: " + getResult());
158-
else if (!getExpectFail().toString().contains(error.toString().substring(0, Math.min(200, error.toString().length()))))
158+
else if (!getExpectFail().toString().contains(error.toString().replace('\n', ' ').substring(0, Math.min(200, error.toString().length()))))
159159
fail("test should fail with " + getExpectFail() + " but failed with: " + error);
160160
return true;
161161
}

0 commit comments

Comments
 (0)