Test Custom Checks with JUnit

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Test Custom Checks with JUnit

JMiddendorf
This post was updated on .
Hello guys,

In my bachelor-thesis I write some custom checks to check if a class can be just known/used  by it’s interface (Objects have to be created with a factory) and is using composition instead of inheritance (see Java Objects by Interfaces http://www-home.fh-konstanz.de/~haase/joi/joi.pdf).
Now I want to test them with JUnit and integrate them in your sourcecode to be able to contribute the checks.

So I started an eclipse java project, where I integrate your source code and add a package (to make it simple I named them in your style) com.puppycrawl.tools.checkstyle.checks.joi  to the checkstyle src folder containing my custom checks.
In the test src folder I add a package with the same containing the testcases, and the same for the testinput folder.

Now finally comes my problem: When I want to run the ant file build.xml I always get this error message:
compile.tests:
   [depend] Deleted 1 out of date files in 0 seconds
    [javac] Compiling 1 source file to E:\workspace\checkstyle-v5\target\tests
    [javac] E:\workspace\checkstyle-v5\src\tests\com\puppycrawl\tools\checkstyle\checks\joi\JOICreationalPatternCheckTest.java:15: cannot find symbol
    [javac] symbol  : class JOICreationalPatternCheck
    [javac] location: class com.puppycrawl.tools.checkstyle.checks.joi.JOICreationalPatternCheckTest
    [javac]            createCheckConfig(JOICreationalPatternCheck.class);
    [javac]                              ^
    [javac] 1 error

BUILD FAILED

When I delete my Testscases the build process and tests succeeds.
My test case (snipped) locks like this:

package com.puppycrawl.tools.checkstyle.checks.joi;

import java.io.File;

import org.junit.Test;

import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;

public class JOICreationalPatternCheckTest extends BaseCheckTestSupport
{
    @Test
    public void testPrivateConstructor() throws Exception {
        DefaultConfiguration checkConfig =
           createCheckConfig(JOICreationalPatternCheck.class);

        String[] expected = {
        "2:component constructor private"
        };

        verify(checkConfig, getPath("joi" + File.separator + "Komponente.java"), expected);
    }
}

Can you help me?
Do I have to do some more configuration?
I already added my Checks to checkstyle_check.xml and the package to the checkstyle_package.xml.
Thank you very much!
Best regards
Jonas Middendorf (Germany)
Reply | Threaded
Open this post in threaded view
|

Re: Test Custom Checks with JUnit

JMiddendorf
Sorry, my last update was not completely. I was just so happy that the behavior have changed. By analyzing the test report I found out that with  Class.forName(“JOICreationalPatternCheck”) and also new new DefaultConfiguration (“JOICreationalPatternCheck”) a ClassNotFound Exception ist thrown. So I know as much as in the beginning of my Mail. Sorry for the false disalarm.
Hope you still can help me with my problem.

JMiddendorf wrote
Hello guys,

In my bachelor-thesis I write some custom checks to check if a class can be just known/used  by it’s interface (Objects have to be created with a factory) and is using composition instead of inheritance (see Java Objects by Interfaces http://www-home.fh-konstanz.de/~haase/joi/joi.pdf).
Now I want to test them with JUnit and integrate them in your sourcecode to be able to contribute the checks.

So I started an eclipse java project, where I integrate your source code and add a package (to make it simple I named them in your style) com.puppycrawl.tools.checkstyle.checks.joi  to the checkstyle src folder containing my custom checks.
In the test src folder I add a package with the same containing the testcases, and the same for the testinput folder.

Now finally comes my problem: When I want to run the ant file build.xml I always get this error message:
compile.tests:
   [depend] Deleted 1 out of date files in 0 seconds
    [javac] Compiling 1 source file to E:\workspace\checkstyle-v5\target\tests
    [javac] E:\workspace\checkstyle-v5\src\tests\com\puppycrawl\tools\checkstyle\checks\joi\JOICreationalPatternCheckTest.java:15: cannot find symbol
    [javac] symbol  : class JOICreationalPatternCheck
    [javac] location: class com.puppycrawl.tools.checkstyle.checks.joi.JOICreationalPatternCheckTest
    [javac]            createCheckConfig(JOICreationalPatternCheck.class);
    [javac]                              ^
    [javac] 1 error

BUILD FAILED

When I delete my Testscases the build process and tests succeeds.
My test case (snipped) locks like this:

package com.puppycrawl.tools.checkstyle.checks.joi;

import java.io.File;

import org.junit.Test;

import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;

public class JOICreationalPatternCheckTest extends BaseCheckTestSupport
{
    @Test
    public void testPrivateConstructor() throws Exception {
        DefaultConfiguration checkConfig =
           createCheckConfig(JOICreationalPatternCheck.class);

        String[] expected = {
        "2:component constructor private"
        };

        verify(checkConfig, getPath("joi" + File.separator + "Komponente.java"), expected);
    }
}

Can you help me?
Do I have to do some more configuration?
I already added my Checks to checkstyle_check.xml and the package to the checkstyle_package.xml.
Thank you very much!
Best regards
Jonas Middendorf (Germany)
Reply | Threaded
Open this post in threaded view
|

Re: Test Custom Checks with JUnit

JMiddendorf
In reply to this post by JMiddendorf
Finally I could fix the problem.
It was an IDE problem. After I integrate the checkstyle sourcecode in a new eclipse project, my mistake was to add my checks per drag&drop over the IDE interface. Eclipse didn’t copied the source files to the correct src/checkstyle folder, it just showed a link to the file. After I copied my files to the correct folder the test and build process succeeds.

JMiddendorf wrote
Hello guys,

In my bachelor-thesis I write some custom checks to check if a class can be just known/used  by it’s interface (Objects have to be created with a factory) and is using composition instead of inheritance (see Java Objects by Interfaces http://www-home.fh-konstanz.de/~haase/joi/joi.pdf).
Now I want to test them with JUnit and integrate them in your sourcecode to be able to contribute the checks.

So I started an eclipse java project, where I integrate your source code and add a package (to make it simple I named them in your style) com.puppycrawl.tools.checkstyle.checks.joi  to the checkstyle src folder containing my custom checks.
In the test src folder I add a package with the same containing the testcases, and the same for the testinput folder.

Now finally comes my problem: When I want to run the ant file build.xml I always get this error message:
compile.tests:
   [depend] Deleted 1 out of date files in 0 seconds
    [javac] Compiling 1 source file to E:\workspace\checkstyle-v5\target\tests
    [javac] E:\workspace\checkstyle-v5\src\tests\com\puppycrawl\tools\checkstyle\checks\joi\JOICreationalPatternCheckTest.java:15: cannot find symbol
    [javac] symbol  : class JOICreationalPatternCheck
    [javac] location: class com.puppycrawl.tools.checkstyle.checks.joi.JOICreationalPatternCheckTest
    [javac]            createCheckConfig(JOICreationalPatternCheck.class);
    [javac]                              ^
    [javac] 1 error

BUILD FAILED

When I delete my Testscases the build process and tests succeeds.
My test case (snipped) locks like this:

package com.puppycrawl.tools.checkstyle.checks.joi;

import java.io.File;

import org.junit.Test;

import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;

public class JOICreationalPatternCheckTest extends BaseCheckTestSupport
{
    @Test
    public void testPrivateConstructor() throws Exception {
        DefaultConfiguration checkConfig =
           createCheckConfig(JOICreationalPatternCheck.class);

        String[] expected = {
        "2:component constructor private"
        };

        verify(checkConfig, getPath("joi" + File.separator + "Komponente.java"), expected);
    }
}

Can you help me?
Do I have to do some more configuration?
I already added my Checks to checkstyle_check.xml and the package to the checkstyle_package.xml.
Thank you very much!
Best regards
Jonas Middendorf (Germany)