GithubHelp home page GithubHelp logo

mixermachine / base-test Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 3.0 165 KB

Automated testing of Java classes via reflections

Java 99.78% Batchfile 0.09% Shell 0.12%
automatic automatic-testing getter java reflection reflection-library setter test testing testing-library

base-test's People

Contributors

dependabot[bot] avatar mixermachine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

base-test's Issues

Rework TestDataProvider

Split up the logic and the basic providerMap supplier so one can build their own custom TestDataProvider

Wrapped primitives do not use origin primitive

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.

Regex in GetterIsSetterCheck

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.

Introduce strict mode

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)

Add separate getter and setter checks

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

Equals is not fully tested when extending objects

Situation

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())));
	}
}

Issue

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.

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.