Skip to content
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

Add junit compilation test integration #148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

XDean
Copy link

@XDean XDean commented May 11, 2018

Add support to quick build compile-period or compilation test in JUnit.

  1. Compile period test. Use @Compile on your test method.
@Test
@Compile(sources = "/HelloWorld.java")
public void test(RoundEnvironment env) {
  // Now you are in compile (Annotation Processor) context which is compiling your sources.
}
  1. Compilation test. Use @Compiled on your test method.
@Test
@Compiled(sources = "/HelloWorld.java")
public void test(Compilation c) {
  // Now your sources have been compiled.
  // Do assert on the Compilation.
}

@ronshapiro
Copy link
Contributor

This surely is interesting, but I don't see the value of using an annotation vs. defining this code in a java method.

It seems like the main benefit is that you can specify the files directly via strings and omit the JavaFileObjects.fromResource() invocation. Not sure how valuable that is (maybe you can define a utility function?)

The downsides that initially come to my mind are:

  • you can't specify different compilers
  • you can't use JavaFileObjects.forSourceLines()
  • because there's no reference to a JavaFileObject, you can't refer to a particular line when you want to reference an diagnostic
  • if we implement a JUnit runner, we're stuck not being able to use other runners like Parameterized without totally changing the way the tests are written.

@XDean
Copy link
Author

XDean commented May 12, 2018

@ronshapiro Yes, you are right. @Compiled is just an abridge of Compile...JavaFileObjects....
But @Compile really has its value.

This project name is 'compile-testing', but it is only care about the compile result not the compile itself. For example

  1. Someone is developing some utilities for AnnotationProcessor, how can it be tested?
  2. Someone is developing an annotation processor. But he want to do a unit test for some methods. how can he test it?

Use @Compile can quick build a compile-period test, which is (I think) also 'Compile-Testing'.

XDean added a commit to XDean/AnnotationProcessorToolkit that referenced this pull request May 15, 2018
I have create [pull
request](google/compile-testing#148) to google
compile-test project. But before it merged, I reserve the copyright.
@XDean
Copy link
Author

XDean commented May 15, 2018

@ronshapiro And for your 4 points

you can't specify different compilers.

I can add support if anyone want.

you can't use JavaFileObjects.forSourceLines()

Although I can add support, I think is a bad usage. You should extract source code into new file instead of embed in your test code. But if you really need it, I can support it.

because there's no reference to a JavaFileObject, you can't refer to a particular line when you want to reference an diagnostic

I can't understand your use case. You can get JavaFileObject from the Diagnostic and its name by getName. If you really want the reference, it's ok to use simple @Test junit test method in CompileTestCase.

if we implement a JUnit runner, we're stuck not being able to use other runners like Parameterized without totally changing the way the tests are written.

Yes, it is. But it's not a problem as you can't use MockitoRunner with Parameterized together. No framework can cover all complex requirement.

XDean added a commit to XDean/compile-testing that referenced this pull request May 16, 2018
I have create [pull
request](google/compile-testing#148) to google
compile-test project. But before it merged, I reserve the copyright.
XDean added a commit to XDean/compile-testing that referenced this pull request May 16, 2018
I have create [pull
request](google/compile-testing#148) to google
compile-test project. But before it merged, I reserve the copyright.
@cpovirk cpovirk added P4 type=addition A new feature labels Jan 13, 2020
@stauvel
Copy link

stauvel commented Feb 25, 2020

No activity since 2 years here... Is there anyone to accept this PR ?

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

Successfully merging this pull request may close these issues.

5 participants