google / gwtmockito

Better GWT unit testing
https://google.github.io/gwtmockito
Apache License 2.0
157 stars 51 forks source link

gwtmockito&maven #16

Closed avetokhin closed 10 years ago

avetokhin commented 11 years ago

Hi. I'm trying to write unit tests for our project using gwtmockito, but I have a problem: gwtmockito cannot find my test classes. I wrote simple test application with one test only. My POM file:

<groupId>simple_test</groupId>
<artifactId>simple_test</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
    </dependency>
    <dependency>
        <groupId>com.google.gwt.gwtmockito</groupId>
        <artifactId>gwtmockito</artifactId>
        <version>1.1.1</version>
    </dependency>
</dependencies>

My test:

package com.test;

import com.google.gwtmockito.GwtMockitoTestRunner; import org.junit.Test; import org.junit.runner.RunWith;

@RunWith(GwtMockitoTestRunner.class) public class SimpleTest {

@Test
public void test() {

}

}

When I run it using maven I have an exception java.lang.ClassNotFoundException: caught an exception while obtaining a class file for com.test.SimpleTest. But it works ok when I run it in IntelliJ IDEA "Run 'SimpleTest'".

What am I doing wrong?

Thank you.

ekuefler commented 11 years ago

What version of Maven are you using? I just tried putting together a minimal example based on your pom.xml and test file and everything worked fine. My pom.xml looks like this:

<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>simple_test</groupId>
  <artifactId>simple_test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.9</version>
    </dependency>
    <dependency>
      <groupId>com.google.gwt.gwtmockito</groupId>
        <artifactId>gwtmockito</artifactId>
        <version>1.1.1</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

And my test file looks like this:

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.ui.Label;
import com.google.gwtmockito.GwtMockitoTestRunner;

@RunWith(GwtMockitoTestRunner.class)
public class SimpleTest {
    @Test
    public void test() {
        GWT.create(Label.class);
    }
}

The directory structure looks like this:

.
├── pom.xml
└── src
    └── test
        └── java
            └── SimpleTest.java

mvn --version says I'm at 3.0.4, and running mvn test causes things to build without errors. Only problem I can think of is an old Maven version, can you check this?

avetokhin commented 11 years ago

Thank you for your answer. My maven version is 3.0.4. I run it with parameter -DforkMode=never to enable debug in IDEA. As I can see without this parameter it works ok.

ekuefler commented 10 years ago

Cool, glad you got it working