Closed abergmeier closed 1 year ago
You can add data = [":test_lib"]
:
java_test(
name = "my-test",
data = [":test_lib"]
args = [
"-testjar",
"$(location :test_lib)", # Same problem with $(execpath :test_lib)
],
main_class = "org.testng.TestNG",
use_testrunner = False,
runtime_deps = [
":test_lib",
See https://bazel.build/reference/be/common-definitions#typical.data
@sgowroji and @navca kindly help on this;
I have a test project, it is configured with maven and TestNG, it works perfectly fine with it. I want to use Bazel to run the same project. I have created WORKSPACE and BUILD files for each directory, which builds perfectly fine. I want to run the test using the 'testng_regressions.xml' in this direcotry: src/test/resources/testrunners/testng_regressions.xml
This is the BUILD file for 'testng_regressions.xml',
load("@rules_java//java:defs.bzl", "java_test")
java_library(
name = "main_project_files",
srcs = glob(['src/main/java/**/*.java']),
runtime_deps = [
"//Web/src/main/java/io/package/com/constants:app_constants",
"//Web/src/main/java/io/package/com/factory:playwright_factory",
"//Web/src/main/java/io/package/com/listeners:extent_report_listener",
"//Web/src/main/java/io/package/com/pages:login_page",
"//Web/src/main/java/io/package/com/steps:login_steps",
],
)
java_library(
name = "test_project_files",
srcs = glob(['src/test/java/**/*.java']),
runtime_deps = [":main_project_files",
"//Web/src/test/java/io/package/com/base:base_test",
"//Web/src/test/java/io/package/com/tests:project_test_files"],
)
#
java_test(
name = "testng_regressions",
size = "small",
timeout = "short",
tags = ["regression"],
runtime_deps = [
":main_project_files",
":test_project_files"
],
use_testrunner = False,
main_class='org.testng.TestNG',
args=['-testjar','libtest_project_files.jar','-verbose','2'],
)
This is the content of the testNG file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Open Cart Test Regression PW Suite" thread-count="5"
parallel="tests" verbose="4">
<listeners>
<listener class-name="io.christdoes.com.listeners.ExtentReportListener" />
</listeners>
<test name="Open Cart Home Page Test_chrome">
<parameter name="browser" value="chrome" />
<parameter name="language" value="en" />
<classes>
<class name="io.christdoes.com.tests.HomePageTest" />
</classes>
</test>
<test name="Open Cart Login Page Test_safari">
<parameter name="browser" value="safari" />
<parameter name="language" value="nl" />
<classes>
<class name="io.christdoes.com.tests.HomePageTest" />
</classes>
</test>
</suite>
When I run the test, it always give a non-detailed error
FAIL: //Web/src/test/resources/testrunners:testng_regressions (see /private/var/tmp/_bazel_christdoes/44565daf5d57f20e3e02fd7160ffadab/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/Web/src/test/resources/testrunners/testng_regressions/test.log)
INFO: Elapsed time: 91.557s, Critical Path: 31.65s
INFO: 17 processes: 3 internal, 6 darwin-sandbox, 8 worker.
INFO: Build completed, 1 test FAILED, 17 total actions
//Web/src/test/resources/testrunners:testng_regressions FAILED in 2.1s
/private/var/tmp/_bazel_user/44565daf5d57f20e3e02fd7160ffadab/execroot/__main__/bazel-out/darwin-fastbuild/testlogs/Web/src/test/
@sgowroji , please kindly share the slack channel. I'll also post it as a new issue.
Description of the problem / feature request:
It is currently unclear how to tell TestNG how to test a (java) library.
Most straight forward approach would be:
This does not work an gives the error:
label '//foo:test_lib' in $(location) expression is not a declared prerequisite of this rule
.How should one reference the runtime dependency instead?
What operating system are you running Bazel on?
Ubuntu 18.04.
What's the output of
bazel info release
?