Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalArgumentException: null type argument at index 1 when executing tests generated by testcasegenerator plugin version 5.2.3 #644

Open
GiuseppePorcaro opened this issue Jul 25, 2023 · 0 comments

Comments

@GiuseppePorcaro
Copy link

Hello, I searched for the bug in question and couldn't find it. Maybe it's not a bug, but I might have misunderstood something.

I am using Crawljax version 5.2.3 along with the Testcasegenerator plugin version 5.2.3 to explore a website and automatically generate test cases (For research purposes with my university.).
I also want to specify that using Crawljax and Testcasegenerator version 4.1 works correctly.

So, I start the runner on a website, it explores it, and eventually, it generates the files eventables.json, Generatedtests.java, states.json. I copy these files to the Maven test folder and run the tests from the IDE (I also tried with mvn test), but I always get the same error when creating a new TestSuiteHelper object. When debugging, it seems that the issue arises from line 266 of the TestSuiteHelper class, which tries to create a map using eventable.json, but it throws a null pointer exception. This one:
mapEventables = gson.fromJson( new BufferedReader(new FileReader(jsonEventables)), new TypeToken<Map<Long, Eventable>>() {}.getType());
jsonEventables is created at line 192.

The same line of code works correctly with version 4.1. Now, I'm not sure if it's a bug in the generation process or if I made a mistake in the configuration with the new version (5.2.3).

Here's the Error, Crawljax code and pom (I wont include the URLs and local paths because I'm not sure if it could be a problem to post them here. However, I assure you that they are correct):

Error:

java.lang.IllegalArgumentException: null type argument at index 1
	at org.apache.commons.lang3.Validate.noNullElements(Validate.java:500)
	at org.apache.commons.lang3.reflect.TypeUtils.parameterizeWithOwner(TypeUtils.java:1642)
	at org.apache.commons.lang3.reflect.TypeUtils.parameterize(TypeUtils.java:1563)
	at com.crawljax.plugins.testcasegenerator.util.GsonUtils$ImmutableListDeserializer.deserialize(GsonUtils.java:35)
	at com.crawljax.plugins.testcasegenerator.util.GsonUtils$ImmutableListDeserializer.deserialize(GsonUtils.java:29)
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:76)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.readIntoField(ReflectiveTypeAdapterFactory.java:212)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$FieldReflectionAdapter.readField(ReflectiveTypeAdapterFactory.java:433)
	at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:393)
	at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:186)
	at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:144)
	at com.google.gson.Gson.fromJson(Gson.java:1227)
	at com.google.gson.Gson.fromJson(Gson.java:1137)
	at com.google.gson.Gson.fromJson(Gson.java:1107)
	at com.crawljax.plugins.testcasegenerator.TestSuiteHelper.init(TestSuiteHelper.java:266)
	at com.crawljax.plugins.testcasegenerator.TestSuiteHelper.<init>(TestSuiteHelper.java:199)
	at generated.GeneratedTests.oneTimeSetUp(GeneratedTests.java:56)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
	at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
	at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:361)
	at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:296)
	at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:180)
	at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.testng.TestRunner.privateRun(TestRunner.java:829)
	at org.testng.TestRunner.run(TestRunner.java:602)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:437)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:431)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:391)
	at org.testng.SuiteRunner.run(SuiteRunner.java:330)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1256)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1176)
	at org.testng.TestNG.runSuites(TestNG.java:1099)
	at org.testng.TestNG.run(TestNG.java:1067)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

Runner:

public class RunCrawler {
    private static final long WAIT_TIME_AFTER_EVENT = 200;
    private static final long WAIT_TIME_AFTER_RELOAD = 50;
    private static final String URL = ""; 

    public static void main(String[] args) throws Exception {

        CrawljaxConfiguration.CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(URL);
        builder.crawlRules().setFormFillMode(CrawlRules.FormFillMode.NORMAL);
        builder.setStateVertexFactory(new DHashStateVertexFactory());

        // click these elements
        builder.crawlRules().clickDefaultElements();
        // builder.crawlRules().click("div");
        builder.crawlRules().crawlHiddenAnchors(true);

        builder.setMaximumStates(5);
        builder.setMaximumDepth(3);
        builder.crawlRules().clickElementsInRandomOrder(false);

        // Set timeouts
        builder.crawlRules().waitAfterReloadUrl(WAIT_TIME_AFTER_RELOAD, TimeUnit.MILLISECONDS);
        builder.crawlRules().waitAfterEvent(WAIT_TIME_AFTER_EVENT, TimeUnit.MILLISECONDS);

        builder.setBrowserConfig(new BrowserConfiguration(EmbeddedBrowser.BrowserType.FIREFOX_HEADLESS, 1));

        builder.addPlugin(new CrawlOverview());
        builder.addPlugin(new TestSuiteGenerator()); //builder.addPlugin(new TestSuiteGenerator(new TestConfiguration(TestConfiguration.StateEquivalenceAssertionMode.BOTH)));


        CrawljaxRunner crawljax = new CrawljaxRunner(builder.build());
        crawljax.call();
    }
}

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>crawljax-test-gen</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.crawljax/crawljax-core -->
        <dependency>
            <groupId>com.crawljax</groupId>
            <artifactId>crawljax-core</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.crawljax.plugins</groupId>
            <artifactId>testcasegenerator</artifactId>
            <version>5.2.3</version>
        </dependency>
    </dependencies>

</project>

oneTimeSetUp() is the method where the TestSuiteHelper object is created and where the null .

public class GeneratedTests {
    private final String URL = "";
	private TestSuiteHelper testSuiteHelper;
	
	private final String CRAWL_PATH = "";

	private StateEquivalenceAssertionMode assertionMode = StateEquivalenceAssertionMode.FRAG;
	private final int $velocityCount = 0;

	private CrawljaxConfiguration getTestConfiguration() {
		CrawljaxConfigurationBuilder builder = CrawljaxConfiguration.builderFor(URL);
		builder.crawlRules().waitAfterEvent(200, TimeUnit.MILLISECONDS);
		builder.crawlRules().waitAfterReloadUrl(50, TimeUnit.MILLISECONDS);
		builder.setBrowserConfig(new BrowserConfiguration(BrowserType.FIREFOX_HEADLESS, 1, new BrowserOptions(-1, true)));
		return builder.build();
	}	
	
	@BeforeClass
	public void oneTimeSetUp(){
		try {
			//load needed data from json files
			testSuiteHelper = new TestSuiteHelper( //here crashes and wont execute test cases
					getTestConfiguration(),
					CRAWL_PATH, URL, false);
					
		}
		catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.getMessage());
		}
	}
.
.
.

I hope I have described the problem well, and I hope you can help me. However, for now, I'll report it as a bug and continue using version 4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant