devjeetr / DeepTC-Enhancer-Improving-the-Readability-of-Automatically-Generated-Tests

Replication package for our ASE 2020 Paper
3 stars 1 forks source link

Not all assert statements are being summarized. #4

Open Brittany-Reid opened 3 years ago

Brittany-Reid commented 3 years ago

Hello guys, cool tool!

I try the example from the paper:

(def method "URI primaryKeyUri = MockURI.aFTPURI;
    KeycloakUriBuilder uriBuilder = KeycloakUriBuilder.fromUri(primaryKeyUri);
    String host = uriBuilder.getHost();
    assertEquals((-1), uriBuilder.getPort());
    assertNotNull(host);")

When I use the following code to generate a summary, where construct-ast-and-get-node and its called functions are copied from helpers.clj

(ns code2sum.core 
  (:require [javaparser-wrapper.core :as j]
            [summarizer.core :as s]
            [ast-extractor.extractable :refer [extract-ast-data]])
  (:import (com.github.javaparser.ast.body MethodDeclaration))
)

(def jn (construct-ast-and-get-node MethodDeclaration method))

(def ast (extract-ast-data jn))

(def result (s/describe-test-method ast))

(doseq [item result]
    (println item)
    (println ""))

I get the output:

Instantiates a new URI named primaryKeyUri

Instantiates a new KeycloakUriBuilder named uriBuilder

Instantiates a new String named host

nil

nil

I tried different examples of assertEquals but can never get a summary.

I notice I get errors from JavaParser often. For example, the example I copied from a test case:

(def method "Option x = new Option();\nOption y = new Option();\nx.setOption(\"hello\");\n")

Outputs:

21-04-13 07:48:07 UnknownHost WARN [javaparser-wrapper.core:58] - Illegal StateException while trying to resolve node  x.setOption("hello")
21-04-13 07:48:12 UnknownHost WARN [javaparser-wrapper.core:58] - Illegal StateException while trying to resolve node  new Option()
21-04-13 07:48:12 UnknownHost WARN [javaparser-wrapper.core:58] - Illegal StateException while trying to resolve node  new Option()

Instantiates a new Option named x

Instantiates a new Option named y

Sets x's option

I've used JavaParser in the past, these might just be warnings for trying to resolve the undefined Options object, and unrelated.

I also noticed that try statements do not work, with the error message "Statement type not supported: TryStmt", for example this test case from Apache CommonsIO

  (def method "
        final PathFilter pathFilter = new NameFileFilter(PATH_FIXTURE);
        try (final DirectoryStream<Path> stream = PathUtils.newDirectoryStream(PathUtils.current(), pathFilter)) {
            final Iterator<Path> iterator = stream.iterator();
            final Path path = iterator.next();
            assertEquals(PATH_FIXTURE, path.getFileName().toString());
            assertFalse(iterator.hasNext());
        }")

If this is intended let me know.

Am I doing something wrong? I can see multiple examples in the paper using assertEquals(). I'd like to evaluate how well the tool preforms, so having it preform as intended is important :). I am using Java 16, but what versions of Java, Clojure etc did you guys use?

Thanks for any help!