mixermachine / base-test Goto Github PK
View Code? Open in Web Editor NEWAutomated testing of Java classes via reflections
Automated testing of Java classes via reflections
Sometimes there might not be a pair of getter and setter for a hidden variable.
Implement separate checks for getter and setter. Work with reflections to view/edit internal variables
Sometimes when executing checks certain variables are ignored.
For example in the getterIsSetterCheck when there is no setter for a getter, this getter will be ignored and the test will still succeed.
Introduce a strict mode in which this would fail a test.
The failing parts should be manually excludable (via regex or direct string compare)
fill class java.time.Instant fails
https://github.com/Mixermachine/base-test/tree/master/src/main/java/de/a9d3/testing/method_extractor
Optionally ignore static non final values
Should use TestDataProvider.fill and invoke all setters with null.
Create reusable logic as this is also need in #8
When we generate a wrapped primitive, we expect that the wrapped primitive uses the primitive internaly.
Currently the providerMap of the TestDataStatics class holds Null values for wrapped primitives (e.g. java.lang.Float, java.lang.Double, ...).
The generation still works, because the later stages of the generation use a best effort approach to then fill the wrapped primitive, but this no longer guarantees the value equivalence between for example java.lang.Double and double.
Correctly the singleThreadExecuter executes all test in a row.
Errors are displayed above the final result and thus it might be unclear what actually failed the specific test.
Collect the error logs and display them in the final result
false is the default value for boolean, always set to true to differentiate between set/unset instances
Should check if all internal variables are present in toString return value
Checker should catch all known exceptions so the user can execute all checker to get a better overview of the state without being interrupted
I noticed flaky tests with objects that have java.util.Date()
attributes. The HashcodeAndEqualsCheck fails sometimes. Maybe because the default new Date()
doesn't always produce equal instances.
Instead use TestDataProvider and execute all setter with (null) to get internal null values
Hello devs,
how can I use the regex to ignore some Checks in Getter and Setter?
I have following code:
private final Long id;
public Person(final Long pId){
this.id = pId;
)
public Long getId()
{
return this.id;
}
public void setId(final Long pId)
{
throw new RuntimeException();
}
How can I use the regex parameter in GetterIsSetterCheck? If I use "id"
, it does not ignore the methods.
Print method which failed the test
There are two classes that extend each other. The methods hashCode()
and equals()
were both generated by Eclipse.
public class Parent {
int foo;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + foo;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Parent other = (Parent) obj;
if (foo != other.foo)
return false;
return true;
}
}
public class Child extends Parent {
int bar;
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + bar;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Child other = (Child) obj;
if (bar != other.bar)
return false;
return true;
}
}
This is the base test for the class Child:
public class ChildTest {
@Test
public void baseTest() {
SingleThreadExecutor executor = new SingleThreadExecutor();
assertTrue(executor.execute(Child.class,
Arrays.asList(new GetterIsSetterCheck(), new HashcodeAndEqualsCheck(), new PublicVariableCheck())));
}
}
The following line in the Childs function equals()
is not tested:
if (getClass() != obj.getClass())
return false;
I guess it needs an object that is an instance of Parent
but not a Child
to test this case.
Split up the logic and the basic providerMap supplier so one can build their own custom TestDataProvider
Sonar reports incomplete test coverage if @EqualsAndHashCode annotation in Lombok is used
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.