Skip to content

Commit e415814

Browse files
Merge branch 'main' into Vassiliy-Kudryashov/1149-only-one-of-generated-tests-is-run-with-generate-and-run
2 parents fcae703 + 40cedc6 commit e415814

File tree

26 files changed

+736
-255
lines changed

26 files changed

+736
-255
lines changed

.github/workflows/publish-plugin-and-cli.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ on:
88
jobs:
99
publish_plugin_and_cli:
1010
uses: ./.github/workflows/publish-plugin-and-cli-from-branch.yml
11+
with:
12+
minor-release: 'none'
1113
secrets: inherit

CONTRIBUTING.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ We welcome absolutely everyone. With one big and kind request: please follow the
1717

1818
There are so many ways to contribute. Choose yours and find the relevant short guide below.
1919

20-
|(1) Choose what you like and check the guideline:| (2) Contribute: |
21-
|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
22-
|Reporting a bug| Create a [bug reporting issue](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=bug_report.md&title=) |
23-
|Suggesting a feature| Create a [feature suggestion issue](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=feature_request.md&title=) |
24-
|Contributing the code (bug fix or feature implementation)| Create a pull request |
25-
|Reproducing a reported bug| Comment on the issue |
26-
|Testing a pull request| Comment on the pull request |
27-
|Improving documentation| Create an issue<br/>Create a pull request<br/>Comment on issues and PRs |
28-
|Sharing ideas| Start the [Discussion](https://github.com/UnitTestBot/UTBotJava/discussions) or join the existing one |
20+
| (1) Choose what you like and check the guideline: | (2) Contribute: |
21+
|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
22+
| [Reporting a bug](#Reporting-a-bug) | Create a [bug reporting issue](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=bug_report.md&title=) |
23+
| [Requesting a feature](#Requesting-a-feature) | Create a [feature suggestion issue](https://github.com/UnitTestBot/UTBotJava/issues/new?assignees=&labels=&template=feature_request.md&title=) |
24+
| [Contributing the code (bug fix or feature implementation)](#Contributing-the-code-(bug-fix-or-feature-implementation)) | Create a pull request |
25+
| [Reproducing a reported bug](#Reproducing-a-reported-bug) | Comment on the issue |
26+
| [Testing a pull request](#Testing-a-pull-request) | Comment on the pull request |
27+
| [Improving documentation](#Improving-documentation) | Create an issue<br/>Create a pull request<br/>Comment on issues and PRs |
28+
| [Sharing ideas](#Sharing-ideas) | Start the [Discussion](https://github.com/UnitTestBot/UTBotJava/discussions) or join the existing one |
2929

3030
# How to submit a contribution
3131

@@ -114,4 +114,4 @@ We do our best in reviewing, but we can hardly specify the exact timeout for it.
114114

115115
By contributing, you agree that your contributions will be licensed under the [Apache License 2.0](https://github.com/UnitTestBot/UTBotJava/blob/main/LICENSE).
116116

117-
Feel free to [contact us directly](https://www.utbot.org/contact/) if that's a concern.
117+
Feel free to [contact us directly](https://www.utbot.org/about) if that's a concern.

DEVNOTE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
When you have the forked repository on your local machine, you are almost ready to build your own version of UnitTestBot.
66

7-
💡 Before you start coding, please check the [system requirements](SystemRequirements.md) and find instructions on
7+
💡 Before you start coding, please check the [system requirements](https://github.com/UnitTestBot/UTBotJava/wiki/Check-system-requirements) and find instructions on
88
configuring development environment.
99

1010
💡 Get to know the [code style](https://github.com/saveourtool/diktat/blob/master/info/guide/diktat-coding-convention.md) we are used to.

README.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
👉 Visit the [official UnitTestBot website](https://www.utbot.org/).
77

88
# What is UnitTestBot?
9+
910
UnitTestBot is the tool for **automated unit test generation** and **precise code analysis**. It produces ready-to-use
1011
test
1112
cases for
@@ -17,6 +18,7 @@ The **symbolic execution engine** paired with a **smart fuzzing technique** cons
1718
UnitTestBot represents all the test summaries in a **human-readable format**. The intelligible test method names and comments help you to control the whole testing process. Test failed? The summary refers you to the related branch or the condition under test.
1819

1920
# Get started
21+
2022
Try the **[online demo](https://www.utbot.org/utbot/)** to generate unit tests with one click.
2123

2224
Get to know the **full version** of UnitTestBot plugin with this quick guide:
@@ -25,13 +27,15 @@ Get to know the **full version** of UnitTestBot plugin with this quick guide:
2527
<summary>Install UnitTestBot plugin for IntelliJ IDEA</summary>
2628

2729
Try the most straightforward path to start using UnitTestBot plugin.
28-
1. Please check the [system requirements](SystemRequirements.md).
30+
1. Please check the [system requirements](https://github.com/UnitTestBot/UTBotJava/wiki/Check-system-requirements).
2931
2. Open your IntelliJ IDEA.
30-
3. Go to **File Settings... Plugins Marketplace**.
32+
3. Go to **File > Settings... > Plugins > Marketplace**.
3133
4. In the search field type *UnitTestBot* — you'll see the UnitTestBot plugin page.
3234
5. Press the **Install** button and wait until it changes to **Installed**, then click **OK**.
3335

34-
Now you can find the UnitTestBot plugin enabled in the **File → Settings → Plugins** window.
36+
Now you can find the UnitTestBot plugin enabled in the **File > Settings > Plugins** window.
37+
38+
Do you want to manually choose the build or to update the plugin? Please refer to [Install or update plugin](https://github.com/UnitTestBot/UTBotJava/wiki/Install-or-update-plugin) in our user guide.
3539

3640
____________
3741
</details>
@@ -42,11 +46,15 @@ ____________
4246
Proceed to generating unit tests for the existing Java project. If you don't have one, create it using the [JetBrains tutorial](https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html).
4347

4448
1. Open your Java project in IntelliJ IDEA.
45-
2. Right-click the required package or a file in the Project tool window, scroll the menu down to the bottom and choose **Create Tests with UTBot...**
46-
3. In the **Generate tests with UTBot** window tick the classes or methods you'd like to cover with unit tests and press **OK**.
49+
2. Right-click the required package or a file in the Project tool window, scroll the menu down to the bottom and
50+
choose **Generate Tests with UnitTestBot...**
51+
3. In the **Generate Tests with UnitTestBot** window tick the classes or methods you'd like to cover with unit tests and
52+
press **Generate Tests** or **Generate and Run**.
4753

4854
Now you can see the resulting test class or classes in the Editor tool window.
4955

56+
Need to configure testing framework, mocking strategy or parameterization? Please check all [configuration options](https://github.com/UnitTestBot/UTBotJava/wiki/Fine-tune-test-generation).
57+
5058
____________
5159
</details>
5260

@@ -73,12 +81,15 @@ What can you do with the output?
7381

7482
3. To *view coverage*:
7583

76-
Right-click the test class, choose **More Run/Debug → Run ... with Coverage**.
84+
Right-click the test class, choose **More Run/Debug > Run ... with Coverage**.
85+
86+
Want to know more about test descriptions or SARIF reports? Please learn how to [Get use of test results](https://github.com/UnitTestBot/UTBotJava/wiki/Get-use-of-test-results).
7787

7888
____________
7989
</details>
8090

8191
# Contribute to UnitTestBot
92+
8293
UnitTestBot is an open source project. We welcome everyone who wants to make UnitTestBot better — introduce a new feature or report a bug. We have only one kind request for our contributors: we expect you to prove the necessity and quality of the suggested changes.
8394

8495
How can you do this? Refer to our [Contributing guide](https://github.com/UnitTestBot/UTBotJava/blob/main/CONTRIBUTING.md).
@@ -88,9 +99,11 @@ Feel free to join the [Discussions](https://github.com/UnitTestBot/UTBotJava/dis
8899
And thank you for your time and effort! ⭐
89100

90101
# Find support
91-
Having troubles with using UnitTestBot? Contact us [directly](https://www.utbot.org/contact).
102+
103+
Having troubles with using UnitTestBot? Contact us [directly](https://www.utbot.org/about).
92104

93105
# Find more UnitTestBot products
106+
94107
You can also try [UnitTestBot](https://github.com/UnitTestBot/UTBotCpp) developed especially for C/C++.
95108

96109
You are welcome to [contribute](https://github.com/UnitTestBot/UTBotCpp/blob/main/CONTRIBUTING.md) to it too!

SystemRequirements.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
### To generate tests with UnitTestBot:
66

7-
you have to install IntelliJ IDEA (versions from 2022.1 to 2022.1.4 are supported).
7+
you have to install IntelliJ IDEA (versions from 2022.1 to 2022.2.2 are supported).
88

99
### To contribute to UnitTestBot:
1010

1111
you have to install
1212

13-
- IntelliJ IDEA (versions from 2022.1 to 2022.1.4 are supported);
13+
- IntelliJ IDEA (versions from 2022.1 to 2022.2.2 are supported);
1414

1515
- JDK 11;
1616

docs/RD for UnitTestBot.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# RD
2+
New child process communication involves 3 different things:
3+
1. Lifetimes
4+
2. Rd entities
5+
3. Rdgen
6+
7+
Let's dive in each of them:
8+
9+
## Lifetimes
10+
11+
Imagine an object having some resources that should be freed
12+
when object dies. For this purpose Java introduced interfaces
13+
```Closeable\AutoCloseable```. Also, 2 helper functions were introduced: try-with-resources and Kotlin's ```Closeable.use```. There are several problems:
14+
1. Object's lifetime can be more complicated that ```Closeable.use``` scope.
15+
2. If function parameter is ```Closeable``` - should you close it?
16+
3. Multiple closes.
17+
4. Concurrent closes.
18+
5. If you have several objects that depends on another object's lifetime - how to correctly close all of them with respect to issues 1-4? How to make it simple, convenient and fast?
19+
20+
And so Lifetime was introduced.
21+
### Lifetime:
22+
```Lifetime``` is a class, where you can register callbacks and which can be terminated once, thus executing all registered callbacks.
23+
24+
```Lifetime``` is an abstract class, it's inheritor - ```LifetimeDefinition```. The only difference - only ```LifetimeDefinition``` can be terminated. Though all ```Lifetime``` are instances of ```LifetimeDefinition```, there are some conventions:
25+
1. Do not cast ```Lifetime``` to ```LifetimeDefinion``` unless you are the one who created ```LifetimeDefinition```.
26+
2. If you introduce somewhere ```LifetimeDefinition``` - either attach it to another ```Lifetime``` or provide code that terminates it.
27+
28+
Useful ```Lifetime``` methods:
29+
30+
- ```onTermination``` - Executes lambda/closeable when lifetime terminates. If already terminated - executes instantly. Termination will proceed on thread that called ```LifetimeDefinition.terminate()```. Callbacks will be executed in ***reversed order***, that is LIFO - last added callback will be executed first.
31+
- ```onTerminationIfAlive``` - same as ```OnTermination```, but callback will not be executed if lifetime is not alive.
32+
- ```executeIfAlive``` - executes lambda if lifetime is alive. This method guarantees that lifetime will not be terminated until lambda completes.
33+
- ```createdNested``` - creates child LifetimeDefinition that will be terminated if parent does.
34+
- ```usingNested``` - same as ```createNested```, but like ```Closeable.use``` pattern.
35+
- ```Eternal``` - lifetime that never terminates.
36+
- ```Terminated``` - lifetime that already terminated.
37+
- ```status``` - see [LifetimeStatus.kt](https://github.com/JetBrains/rd/blob/9b806ccc770515f6288c778581c54607420c16a7/rd-kt/rd-core/src/main/kotlin/com/jetbrains/rd/util/lifetime/LifetimeStatus.kt) in RD repo. There are 3 convenient method: ```IsAlive, IsNotAlive, IsTerminated```.
38+
39+
### LifetimeDefinition:
40+
- ```terminate``` - terminates ```Lifetime``` and calls all callbacks. Sometimes if multiple concurrent terminations occurred - method will return before executing all callbacks because some other thread is doing this.
41+
42+
## Rd
43+
Rd is a cross-language, cross-platform, light-weight, reactive, one-to-one rpc protocol. Can work either on the same or different machines via internet.
44+
45+
Useful entities:
46+
- ```Protocol``` - encapsulation of all logic regarding rd communication. All entities should be bound to protocol before using. Contains ```IScheduler``` which executes runnables on different thread.
47+
- ```RdSignal``` - entity for ___fire and forget___. You can add callback for every received message via ```advise(lifetime, callback)``` method. There are 2 interfaces - ```ISink``` which allows only to advise for messages, and ```ISignal``` which can also ```fire``` events. Also, there is just ```Signal``` class with same behaviour, but without remote communication.
48+
49+
___Important___: if you advise and fire from the same process - your callback will receive ___not only___ messages from another process, but also the ones you fire.
50+
- ```RdProperty``` - stateful property. You can get current value, you can advise - advised callback will be executed on current value and on every change.
51+
- ```RdCall``` - remote procedure call.
52+
53+
Also there are ```RdSet```, ```RdMap``` and many other.
54+
55+
There is ```async``` property that allows you to ```fire``` entities from any thread. Otherwise you would need to do it from ```Protocol.scheduler``` thread. All rd entities should be at first
56+
57+
## Rdgen
58+
Generates custom classes and requests which can be bound to protocol and advised. There is special model DSL for it.
59+
### Model DSL
60+
Eexample:
61+
1. [Korifey](https://github.com/korifey/rd_example/blob/main/src/main/kotlin/org/korifey/rd_example/model/Root.kt) - quite simple
62+
2. [Rider Unity plugin](https://github.com/JetBrains/resharper-unity/tree/net223/rider/protocol/src/main/kotlin/model) - complicated one
63+
64+
First you need to define ```Root``` object - only one instance of each root can be assigned to protocol.
65+
66+
Then there is root extension ```Ext(YourRoot)``` where you can define your own types and model entities. You can assign multiple extensions of root for the protocol. Auxillary structures can be defined as direct fields - they will be also generated.
67+
68+
DSL:
69+
- ```structdef``` - structure with fields that cannot be bound to protocol, but can be serialized. Can be open for inheritace - ```openstruct```, can be abstract - ```basestruct```. Can have only ```field``` as member.
70+
- ```classdef``` - class that can be bould to model. Can also have ```property```, ```signal```, ```call``` e.t.c. as members. It is possible to do inheritance - ```openclass```, ```baseclass```.
71+
- ```interfacedef``` - to define interfaces. Use ```method``` to create signature.
72+
73+
You can use ```extends``` and ```implements``` to work with inheritance.
74+
75+
___N.B.___ - rdgen can generate models also for C# and C++. Their structs and classes have a little different behaviour.
76+
- Rd entities - only in bindable models(```Ext```, ```classdef```):
77+
- ```property```
78+
- ```signal```
79+
- ```source```
80+
- ```sink```
81+
- ```array``` and ```immutablelist```
82+
- Useful properties in dsl entities:
83+
- async - as ```async``` in RD entities
84+
- docs - provides kdoc/javadoc for generated entity
85+
### Gradle
86+
[Example](https://github.com/korifey/rd_example/blob/main/build.gradle)
87+
88+
```RdGenExtension``` configurates Rdgen, useful properties:
89+
- ```sources``` - folders with dsl .kt files. If not present, scan classpath for inheritors of ```Root``` and ```Ext```.
90+
- ```hashfile``` - folder to store hash file ```.rdgen``` for incremental generation.
91+
- ```packages``` - java package names to search toplevels, delimited by ','. Example: ```com.jetbrains.rd.model.nova,com,org```.
92+
- Configuring model generation with method ```RdGenExtension.generator```:
93+
- root - for which root you are declaring this generator
94+
- namespace - which namespace should be used in generated source. In kotlin it configures generated packaged name.
95+
- directory - where to put generated files.
96+
- transform - can be ```symmetric```, ```asis``` and ```reversed```. This allows to configure model interface differently for client-server scenarios.
97+
98+
P.S. This is legacy from distant past, in 99% of time you should use ```symmetric```. In 1% chance - consult with somebody if you really need another option.
99+
- language - can be ```kotlin```, ```cpp``` and ```csharp```.
100+
101+
## UtBot project
102+
103+
There is another gradle project ```utbot-rd``` which contains model sources in ```rdgenModels``` sources. Look for ```org.utbot.rd.models.ProtocolRoot```.
104+
105+
Usefull:
106+
1. if you need to use rd somewhere - add following dependencies:
107+
```
108+
implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: 'actual.version'
109+
110+
implementation group: 'com.jetbrains.rd', name: 'rd-core', version: 'actual.version'
111+
```
112+
2. There are some usefull classes to work with processes & rd:
113+
- ```LifetimedProcess``` - binds ```Lifetime``` to process. If process dies - lifetime terminates and vice versa. You can terminate lifetime manually - this will destroy process.
114+
- ```ProcessWithRdServer``` - also starts Rd server and waits for connection.
115+
- ```UtInstrumentationProcess``` - encapsulates logic for preparing child process for executing arbitary commands. Exposes ```protocolModel``` for communicating with child process.
116+
- ```ConcreteExecutor``` is convenient wrapper for executing commands and managing resources.
117+
3. How child communication works:
118+
- Choosing free port
119+
- Creating child process, passing port as argument
120+
- Both processes create protocols and bind model
121+
- Child process setups all callbacks
122+
- Parent process cannot send messages before child creates protocol, otherwise messages will be lost. So child process needs to signal that he is ready.
123+
- Child proces creates special file in temp dir, that is observed by parent process.
124+
- When parent process spots file - he deletes it, and then sends special message for preparing child proccess instrumentation
125+
- Only then process is ready for executing commands
126+
4. How to write custom commands for child process
127+
- Add new ```call``` in ```ProtocolModel```
128+
- Regenerate models
129+
- Add callback for new ```call``` in ```ChildProcess.kt```
130+
- Use ```ConcreteExecutor.withProcess``` method
131+
- ___Important___ - do not add `Rdgen` as implementation dependency, it breaks some `.jar`s as it contains `kotlin-compiler-embeddable`.
132+
5. Logs
133+
134+
There is ```UtRdLogger``` where you can configure level via ```log4j2.xml```.
135+
136+
6. Custom protocol marshalling types
137+
138+
Do not spend time on it until:
139+
- Cyclic dependencies removed from UtModels
140+
- Kotlinx.serialization is used
141+

0 commit comments

Comments
 (0)