@@ -11,12 +11,17 @@ junit_repositories()
1111junit_toolchain()
1212
1313# ScalaTest
14- load(" " @ io_bazel_rules_scala// testing:scalatest.bzl" , " scalatest_repositories" , " scalatest_toolchain" )
14+ load(" @io_bazel_rules_scala//testing:scalatest.bzl" , " scalatest_repositories" , " scalatest_toolchain" )
1515scalatest_repositories()
1616scalatest_toolchain()
17+
18+ # Specs2 with Junit
19+ load(" @io_bazel_rules_scala//testing:specs2_junit.bzl" , " specs2_junit_repositories" , " specs2_junit_toolchain" )
20+ specs2_junit_repositories()
21+ specs2_junit_toolchain()
1722```
1823
19- # ## Example to set up JUnit dependencies
24+ ### Configuring JUnit dependencies via toolchain
2025
2126` BUILD ` file content in your preferred package:
2227``` starlark
@@ -48,13 +53,18 @@ declare_deps_provider(
4853 ],
4954)
5055```
51-
56+ Register toolchain
57+ ``` starlark
58+ # WORKSPACE
59+ register_toolchains(' //my/package:testing_toolchains_with_junit' )
60+ ```
5261` junit_classpath_provider ` (deps_id ` junit_classpath ` ) is where classpath required for junit tests
5362is defined.
5463
55- ScalaTest support can be enabled by configuring a provider with an id `scalatest_classpath` :
64+ ### ScalaTest dependencies can be configured by decalring a provider with an id ` scalatest_classpath ` :
5665
5766``` starlark
67+ # my/package/BUILD
5868scala_testing_toolchain(
5969 name = " testing_toolchains_with_scalatest" ,
6070 dep_providers = [
@@ -80,10 +90,66 @@ declare_deps_provider(
8090 ],
8191)
8292```
83-
84- Toolchain must be registered in your `WORKSPACE ` file :
93+ Register toolchain
8594``` starlark
86- register_toolchains(' //my/package:testing_toolchain' )
95+ # WORKSPACE
96+ register_toolchains(' //my/package:testing_toolchains_with_scalatest' )
8797```
8898
89- Single toolchain can be used to configure multiple testing rules (JUnit 4 , ScalaTest).
99+ ### Specs2 with Junit support can be configured by declaring providers with
100+ ` junit_classpath_provider ` , ` specs2_classpath_provider ` , ` specs2_junit_classpath_provider ` ids:
101+ ``` starlark
102+ # my/package/BUILD
103+ scala_testing_toolchain(
104+ name = " testing_toolchains_with_specs2_junit_impl" ,
105+ dep_providers = [
106+ " :junit_classpath_provider" ,
107+ " :specs2_classpath_provider" ,
108+ " :specs2_junit_classpath_provider" ,
109+ ],
110+ visibility = [" //visibility:public" ],
111+ )
112+
113+ toolchain(
114+ name = " testing_toolchains_with_specs2_junit" ,
115+ toolchain = " :testing_toolchains_with_specs2_junit_impl" ,
116+ toolchain_type = " @io_bazel_rules_scala//testing/toolchain:testing_toolchain_type" ,
117+ visibility = [" //visibility:public" ],
118+ )
119+
120+ declare_deps_provider(
121+ name = " junit_classpath_provider" ,
122+ deps_id = " junit_classpath" ,
123+ visibility = [" //visibility:public" ],
124+ deps = [
125+ " @my_hamcrest_core" ,
126+ " @my_junit" ,
127+ ],
128+ )
129+
130+ declare_deps_provider(
131+ name = " specs2_classpath_provider" ,
132+ deps_id = " specs2_classpath" ,
133+ visibility = [" //visibility:public" ],
134+ deps = [
135+ " @my_specs2_common" ,
136+ " @my_specs2_core" ,
137+ " @my_specs2_fp" ,
138+ " @my_specs2_matcher" ,
139+ ],
140+ )
141+
142+ declare_deps_provider(
143+ name = " specs2_junit_classpath_provider" ,
144+ deps_id = " specs2_junit_classpath" ,
145+ visibility = [" //visibility:public" ],
146+ deps = [
147+ " @my_specs2_junit" ,
148+ ],
149+ )
150+ ```
151+ Register toolchain
152+ ``` starlark
153+ # WORKSPACE
154+ register_toolchains(' //my/package:testing_toolchains_with_specs2_junit' )
155+ ```
0 commit comments