Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Class not found #153

Closed
borkaehw opened this issue Sep 17, 2019 · 9 comments
Closed

Class not found #153

borkaehw opened this issue Sep 17, 2019 · 9 comments

Comments

@borkaehw
Copy link
Contributor

It might be just because I am doing something wrong.

I set up an example by following exactly this README. I see the same test failure messages from //test:test/bazel0.21.0, //test:test/bazel0.22.0, and //test:test/bazel0.23.2.

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //test:test/bazel0.23.2
-----------------------------------------------------------------------------
Class not found: [test.test]

BazelTestRunner exiting with a return value of 2
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.

-- JVM shutdown starting at 2019-09-17 22:35:41 --

I have tried Bazel 0.22.0 and 0.29.0.

@ittaiz
Copy link
Member

ittaiz commented Sep 18, 2019

We need more info. I don't have enough info but my guess is that you have the incorrect target name. java_test has an implicit dependency where it tries to deduce the test class name from the target name.
Can you add an example of your attempt? Btw, see the below example of scala to see how you can decouple it completely.

@borkaehw
Copy link
Contributor Author

Thanks for taking a look. I didn't upload to remote, here are more info. If a remote repo makes solving issue easier, I am happy to do so.

WORKSAPCE

workspace(name = "test")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_integration_testing",
    url = "https://github.com/bazelbuild/bazel-integration-testing/archive/3a6136e8f6287b04043217d94d97ba17edcb7feb.zip",
    type = "zip",
    strip_prefix= "bazel-integration-testing-3a6136e8f6287b04043217d94d97ba17edcb7feb",
    sha256 = "bfc43a94d42e08c89a26a4711ea396a0a594bd5d55394d76aae861b299628dca",
)

load("@build_bazel_integration_testing//tools:bazel_java_integration_test.bzl", "bazel_java_integration_test_deps")
bazel_java_integration_test_deps()

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "f04d2373bcaf8aa09bccb08a98a57e721306c8f6043a2a0ee610fd6853dcde3d",
    urls = [
        "https://github.com/bazelbuild/rules_go/releases/download/0.18.6/rules_go-0.18.6.tar.gz",
    ],
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "7fc87f4170011201b1690326e8c16c5d802836e3a0d617d8f75c3af2b23180c4",
    urls = [
        "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")

go_rules_dependencies()

test/BUILD.bazel

load("@build_bazel_integration_testing//:bazel_integration_test.bzl", "bazel_java_integration_test")

bazel_java_integration_test(
    name = "test",
    srcs = ["ExampleTest.java"],
)

test/ExampleTest.java

package test;

import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import build.bazel.tests.integration.BazelCommand;
import build.bazel.tests.integration.WorkspaceDriver;

import java.io.IOException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class ExampleTest {
  private WorkspaceDriver driver = new WorkspaceDriver();

  @BeforeClass
  public static void setUpClass() throws IOException {
    WorkspaceDriver.setUpClass();
  }

  @Before
  public void setUp() throws Exception {
    driver.setUp();
  }

  @Test
  public void bazelFailure() throws Exception {
    driver.scratchFile("foo/BUILD", "sh_test(name = \"bar\",\n" + "srcs = [\"bar.sh\"])");
    driver.scratchExecutableFile("foo/bar.sh", "echo \"boom\"", "exit -1");

    BazelCommand cmd = driver.bazel("test", "//foo:bar").run();

    assertNotEquals("bazel test return code", 0, cmd.exitCode());
    assertTrue(
        "stderr contains boom failure",
        cmd.errorLines().stream().anyMatch(x -> x.contains("boom")));
  }
}

Then I ran bazel test //test.

@ittaiz
Copy link
Member

ittaiz commented Sep 18, 2019 via email

@borkaehw
Copy link
Contributor Author

Thanks, it works. What's the principle of naming a target?

@ittaiz
Copy link
Member

ittaiz commented Sep 19, 2019 via email

@borkaehw
Copy link
Contributor Author

Sounds good, thanks.

@ZacSweers
Copy link

I'm running into this same issue in https://github.com/google/dagger. I'm not the most well-versed in Bazel, but what's the "target" in this context? In my case I'm just running a simple test from the IDE via the plugin, but the error log file is unhelpful.

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //javatests/dagger/lint:test
-----------------------------------------------------------------------------
/private/var/tmp/_bazel_zsweers/1825c3febee87f83f0190e5ba08c9307/sandbox/darwin-sandbox/2381/execroot/__main__/bazel-out/darwin-fastbuild/bin/javatests/dagger/lint/test.runfiles/__main__/javatests/dagger/lint/test: line 260: fg: no job control
/private/var/tmp/_bazel_zsweers/1825c3febee87f83f0190e5ba08c9307/sandbox/darwin-sandbox/2381/execroot/__main__/bazel-out/darwin-fastbuild/bin/javatests/dagger/lint/test.runfiles/__main__/javatests/dagger/lint/test: line 261: fg: no job control
/private/var/tmp/_bazel_zsweers/1825c3febee87f83f0190e5ba08c9307/sandbox/darwin-sandbox/2381/execroot/__main__/bazel-out/darwin-fastbuild/bin/javatests/dagger/lint/test.runfiles/__main__/javatests/dagger/lint/test: line 262: fg: no job control
Class not found: []

BazelTestRunner exiting with a return value of 2
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.

-- JVM shutdown starting at 2020-04-10 06:30:31 --


load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_test")

package(default_visibility = ["//:src"])

kt_jvm_test(
    name = "test",
    srcs = [
        "DaggerKotlinIssuesDetectorTest.kt",
    ],
    deps = [
        "//java/dagger/lint:dagger_lint",
        "@maven//:org_jetbrains_kotlin_kotlin_stdlib",
        "@maven//:com_android_tools_lint_lint_checks",
        "@maven//:com_android_tools_lint_lint_tests",
        "@maven//:com_android_tools_testutils",
        "@google_bazel_common//third_party/java/junit",
    ]
)

And the logs equally unhelpful

/usr/local/bin/bazel test --tool_tag=ijwb:IDEA:community --curses=no --color=yes --progress_in_terminal_title=no --runs_per_test=1 --flaky_test_attempts=1 --build_event_binary_file=/var/folders/yc/gq1jznyd2hg6q4qgl82m9_z80000gp/T/intellij-bep-7048b81c-22ec-4559-b278-e73c2743fbab --nobuild_event_binary_file_path_conversion --test_filter=dagger.lint.DaggerKotlinIssuesDetectorTest -- //javatests/dagger/lint:test
Loading: 
Loading: 0 packages loaded
INFO: Build options --runs_per_test and --test_filter have changed, discarding analysis cache.
Analyzing: target //javatests/dagger/lint:test (0 packages loaded, 0 targets configured)
Analyzing: target //javatests/dagger/lint:test (109 packages loaded, 841 targets configured)
Analyzing: target //javatests/dagger/lint:test (109 packages loaded, 841 targets configured)
INFO: Analyzed target //javatests/dagger/lint:test (110 packages loaded, 1070 targets configured).
INFO: Found 1 test target...
[0 / 2] [Prepa] BazelWorkspaceStatusAction stable-status.txt
FAIL: //javatests/dagger/lint:test (see /private/var/tmp/_bazel_zsweers/1825c3febee87f83f0190e5ba08c9307/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/javatests/dagger/lint/test/test.log)
Target //javatests/dagger/lint:test up-to-date:
  bazel-bin/javatests/dagger/lint/test.jar
INFO: Elapsed time: 5.485s, Critical Path: 0.57s
INFO: 2 processes: 2 darwin-sandbox.
INFO: Build completed, 1 test FAILED, 2 total actions
//javatests/dagger/lint:test                                             FAILED in 0.3s
  /private/var/tmp/_bazel_zsweers/1825c3febee87f83f0190e5ba08c9307/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/javatests/dagger/lint/test/test.log

Executed 1 out of 1 test: 1 fails locally.
INFO: Build Event Protocol files produced successfully.
INFO: Build completed, 1 test FAILED, 2 total actions
INFO: Build completed, 1 test FAILED, 2 total actions

@ZacSweers
Copy link

PR with my case is here: google/dagger#1805

@ittaiz
Copy link
Member

ittaiz commented Apr 10, 2020

Hi,
Your problem isn't related to this library but rather to rules_kotlin.
You might find a solution in this link but if not I suggest you open an issue over in rules_kotlin.

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

No branches or pull requests

3 participants