-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gradle testAnnotationProcessor for classes under test #164
Comments
Hmmm, the above looks ok to me. Do you want to create a little example project? I can then clone it and look. |
Please have a look at: https://github.com/Travisnv/dinject-test-source-set.git From src/test/java/test I have two client class: If I use default scope (@singleton), compile task work fine. However, if I use custom scope (@TestScope) for client classes, I see following error:
|
*> @TestScope*
Note that there is a built in @TestScope now ... it was added in version
6.13 #155 With the view of
making it easier for component testing. So have a look at that and the
associated tests in case you are looking to do something similar.
I see you are using version6.11 here so in theory that isn't the issue with
this example but note that @TestScope gets special treatment from 6.13
onwards.
I'll see if I can look at this later tonight.
Cheers, Rob.
…On Tue, 23 Nov 2021 at 15:43, Travis Nguyen ***@***.***> wrote:
Please have a look at:
https://github.com/Travisnv/dinject-test-source-set.git
From src/test/java/test I have two client class:
If I use default scope ***@***.*** <https://github.com/singleton>),
compile task work fine. However, if I use custom scope ***@***.***) for
client classes, I see following error:
error: Failed to create module filer Attempt to recreate a file for type test.TestModule
error: Failed to create module filer Attempt to recreate a file for type test.TestModule
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileTestJava'.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABTATP3NDXF4SQIDHKMYP3UNL5UJANCNFSM5IGW3VSQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
… On Tue, 23 Nov 2021 at 15:55, Rob Bygrave ***@***.***> wrote:
*> @TestScope*
Note that there is a built in @TestScope now ... it was added in version
6.13 #155 With the view of
making it easier for component testing. So have a look at that and the
associated tests in case you are looking to do something similar.
I see you are using version6.11 here so in theory that isn't the issue
with this example but note that @TestScope gets special treatment from 6.13
onwards.
I'll see if I can look at this later tonight.
Cheers, Rob.
On Tue, 23 Nov 2021 at 15:43, Travis Nguyen ***@***.***>
wrote:
> Please have a look at:
> https://github.com/Travisnv/dinject-test-source-set.git
>
> From src/test/java/test I have two client class:
>
> If I use default scope ***@***.*** <https://github.com/singleton>),
> compile task work fine. However, if I use custom scope ***@***.***) for
> client classes, I see following error:
>
> error: Failed to create module filer Attempt to recreate a file for type test.TestModule
> error: Failed to create module filer Attempt to recreate a file for type test.TestModule
>
> FAILURE: Build failed with an exception.
>
> * What went wrong:
> Execution failed for task ':compileTestJava'.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#164 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AABTATP3NDXF4SQIDHKMYP3UNL5UJANCNFSM5IGW3VSQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
>
|
I have a look and see we want to archive similar objective: a scope during test. However, rather than having a common test scope, I would like to build scope for every single test of a test suite. Let's say we have a suite with different test classes. Assuming one test class only have 1 test method with 2 events: test starts and test finishes. I want to construct scope per test. Here is an example for two tests: Test 1:
Test 2:
I hook those events by calling scope constructor and scope close on a test listener (a testng specific stuff). |
I would like to build scope for every single test of a test suite.
That is how it works normally now assuming I am interpreting correctly.
That is, this is how virtually all the tests in avaje-inject run now by
creating a new BeanScope for each and every test independently with
virtually all those tests doing that programmatically.
So the built in @TestScope and associated support for junit 5 is all about
the opposite of that - having the globally scoped / wired things that are
expensive (like docker containers).
But yes, we can get what you are looking for in the description above
without need for any custom scope annotation etc. Programmatically just use
try with resources like:
https://github.com/avaje/avaje-inject/blob/master/inject-test/src/test/java/org/example/coffee/fruit/AppleServiceTest.java#L40
…On Tue, 23 Nov 2021 at 17:26, Travis Nguyen ***@***.***> wrote:
I have a look and see we want to archive similar object: a scope during
test. However, rather than having a common test scope, I would like to
build scope for every single test of a test suite.
Let's say we have a suite with different test classes. Assuming one test
class only have 1 test method with 2 events: test starts and test finishes.
I want to construct scope per test. Here is an example for two tests:
Test 1:
- create test scope
- At test starts
- At test finishes
- close test scope
Test 2:
- create test scope
- At test starts
- At test finishes
- close test scope
...
...
repeat for the rest of tests of suite
I hook those events by calling scope constructor and scope close on a test
listener (a testng specific stuff).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABTATKBGH2KJ7WLBTZHPFDUNMJXJANCNFSM5IGW3VSQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Thanks, I did just exactly what you have in sample test class, it works. Can we back a original question: compileTestJava goal when we have: 1.custom scope interface under /src/test/java. I have a few try moving both classes from /src/test/java to /src/main/java. At this time, both compileJava and compileJavaTest finish without any error. |
Yes, I still haven't looked at that git repo yet.
…On Wed, 24 Nov 2021 at 22:20, Travis Nguyen ***@***.***> wrote:
Thanks, I did just exactly what you have in sample test class, it works.
Can we back a original question: compileTestJava goal when we have:
1.custom scope interface
2. classes which is annotated with custom scope
under /src/test/java.
I have a few try moving both classes from /src/test/java to
/src/main/java. At this time, both compileJava and compileJavaTest finish
without any error.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABTATNV7DOKT3EH5WK4HJ3UNSU4PANCNFSM5IGW3VSQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
It is not compiling, gives a NPE during compile
|
Ok, the problem looks like we are trying to create a custom "TestScope" plus a default scope that also gets the same module name based on the package. That is, the custom scope called So for example, there are 3 ways to get this to work:
|
This is because the module name gets derived based on:
... so given these 2 naming conventions both modules get called So making one of those 3 changes should sort it all out. |
I confirmed that both suggestion works for me. Anyway, can we add some documentation about create same name for |
As this stage I still want to treat this as a bug. My idea at the moment is
to detect this sort of name clash and produce a good error message.
So I am planning to keep this open until I have a crack at it. I'm pretty
confident we can detect this and do better here.
Cheers, Rob.
|
Ok, we now detect this module name clash case and throw a reasonable error:
|
Hi,
This is more than a question than a defect. I trying to use dinject for classes under test source set with gradle. For an example:
/src/test/java/
@singleton
public class Client {
}
...
...
@CustomScope
public class Client2 {
}
on build.gradle
I have setup the following:
dependencies {
...
testImplementation group: 'io.avaje', name: 'avaje-inject', version:'6.11'
testAnnotationProcessor group: 'io.avaje', name: 'avaje-inject-generator', version:'6.11'
...
}
on the IDE itself, I see IntelliJ can find generated class from import statement. However, when I issue Gradle task
clean compileJavaTest test
I see gradle complains about not about to find the generated classes from dinject.Can you please have a look and have any direction for using dinject for test source set ?
Thanks and Regards,
Travis
The text was updated successfully, but these errors were encountered: