Skip to content

Commit 3c78560

Browse files
Add UTBot Java
1 parent ce7852c commit 3c78560

File tree

987 files changed

+105462
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

987 files changed

+105462
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: UTBot Java build and run tests
2+
3+
on:
4+
workflow_dispatch
5+
6+
jobs:
7+
build-utbot-java:
8+
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-java@v2
13+
with:
14+
java-version: '8'
15+
distribution: 'zulu'
16+
java-package: jdk+fx
17+
- uses: gradle/gradle-build-action@v2
18+
with:
19+
gradle-version: 6.8
20+
21+
- name: Build UTBot Java
22+
run: |
23+
export KOTLIN_HOME="/usr"
24+
gradle clean build
25+
26+
- name: Upload utbot-framework logs
27+
if: ${{ always() }}
28+
uses: actions/upload-artifact@v2
29+
with:
30+
name: utbot_framework_logs
31+
path: utbot-framework/logs/*
32+
33+
- name: Create tests report archive if tests have failed
34+
if: ${{ failure() }}
35+
run: |
36+
cd utbot-framework/build/reports/tests/test
37+
tar -czpf tests_run_report.tar.gz *
38+
39+
- name: Upload tests report artifacts if tests have failed
40+
if: ${{ failure() }}
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: tests_run_report.tar.gz
44+
path: utbot-framework/build/reports/tests/test/tests_run_report.tar.gz
45+
46+
- name: Create IntelliJ IDEA plugin tests report archive if tests have failed
47+
if: ${{ failure() }}
48+
run: |
49+
cd utbot-intellij/build/reports/tests/test
50+
tar -czpf intellij_plugin_tests_run_report.tar.gz *
51+
52+
- name: Upload IntelliJ IDEA plugin tests report artifacts if tests have failed
53+
if: ${{ failure() }}
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: intellij_plugin_tests_run_report.tar.gz
57+
path: utbot-intellij/build/reports/tests/test/intellij_plugin_tests_run_report.tar.gz
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: UTBot Java build and run tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-utbot-java:
11+
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
12+
runs-on: ubuntu-20.04
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-java@v2
16+
with:
17+
java-version: '8'
18+
distribution: 'zulu'
19+
java-package: jdk+fx
20+
- uses: gradle/gradle-build-action@v2
21+
with:
22+
gradle-version: 6.8
23+
24+
- name: Build UTBot Java
25+
run: |
26+
export KOTLIN_HOME="/usr"
27+
gradle clean build
28+
29+
- name: Upload utbot-framework logs
30+
if: ${{ always() }}
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: utbot_framework_logs
34+
path: utbot-framework/logs/*
35+
36+
- name: Create tests report archive if tests have failed
37+
if: ${{ failure() }}
38+
run: |
39+
cd utbot-framework/build/reports/tests/test
40+
tar -czpf tests_run_report.tar.gz *
41+
42+
- name: Upload tests report artifacts if tests have failed
43+
if: ${{ failure() }}
44+
uses: actions/upload-artifact@v2
45+
with:
46+
name: tests_run_report.tar.gz
47+
path: utbot-framework/build/reports/tests/test/tests_run_report.tar.gz
48+
49+
- name: Create IntelliJ IDEA plugin tests report archive if tests have failed
50+
if: ${{ failure() }}
51+
run: |
52+
cd utbot-intellij/build/reports/tests/test
53+
tar -czpf intellij_plugin_tests_run_report.tar.gz *
54+
55+
- name: Upload IntelliJ IDEA plugin tests report artifacts if tests have failed
56+
if: ${{ failure() }}
57+
uses: actions/upload-artifact@v2
58+
with:
59+
name: intellij_plugin_tests_run_report.tar.gz
60+
path: utbot-intellij/build/reports/tests/test/intellij_plugin_tests_run_report.tar.gz
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish utbot-intellij and utbot-cli as an archive
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
publish_utbot_java:
9+
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
10+
runs-on: ubuntu-20.04
11+
env:
12+
VERSION: ${{ format('1.0.{0}', github.run_number) }}
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-java@v2
17+
with:
18+
java-version: '8'
19+
distribution: 'liberica'
20+
java-package: jdk+fx
21+
- uses: gradle/gradle-build-action@v2
22+
with:
23+
gradle-version: 6.8
24+
25+
- name: Build UTBot IntelliJ IDEA plugin
26+
run: |
27+
export KOTLIN_HOME="/usr"
28+
gradle buildPlugin
29+
cd utbot-intellij/build/distributions
30+
mv $(find . -type f -iname "utbot-intellij*.zip") utbot-intellij-${{ env.VERSION }}.zip
31+
unzip utbot-intellij-${{ env.VERSION }}.zip
32+
rm utbot-intellij-${{ env.VERSION }}.zip
33+
- name: Archive UTBot IntelliJ IDEA plugin
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: utbot-intellij-${{ env.VERSION }}
37+
path: utbot-intellij/build/distributions/*
38+
39+
- name: Build UTBot CLI
40+
run: |
41+
export KOTLIN_HOME="/usr"
42+
cd utbot-cli
43+
gradle clean build
44+
cd build/libs
45+
mv $(find . -type f -iname "utbot-cli*.jar") utbot-cli-${{ env.VERSION }}.jar
46+
- name: Archive UTBot CLI
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: utbot-cli-${{ env.VERSION }}
50+
path: utbot-cli/build/libs/utbot-cli-${{ env.VERSION }}.jar

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
out/
2+
tmp/
3+
temp/
4+
logs/
5+
build/
6+
target/
7+
.idea/
8+
.gradle/
9+
*.log

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# How to contribute to UTBot Java
2+
3+
## Want a new feature or change existing one?
4+
* Create an issue with proposal and describe your idea
5+
* Wait for our feedback, it will be decided who is preparing the pull request: we may need your help or fix on our side
6+
7+
## Found a defect?
8+
Ensure this defect wasn't already reported in our [Issues](https://github.com/UnitTestBot/UTBotCpp/issues)
9+
10+
If not - create a new one containing:
11+
* Environment *(describe your full setup)*
12+
* Pre-Conditions *(some special prerequisites)*
13+
* Steps to reproduce *(to be on the same page)*
14+
* Actual and expected result *(what went wrong?)*
15+
16+
If you already have a PR with solution - link it with the created issue.
17+
18+
## How to setup development environment?
19+
20+
Please refer [Developer guide](DEVNOTE.md) to setup developer environment, build and run UTBot.
21+
22+
## How to test you PR?
23+
24+
Currently, not all checks are automized. It's required to do manual testing after PR.

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# UTBotJava
1+
[![Build UTBot and run unit tests](https://github.com/UnitTestBot/UTBotJava/actions/workflows/build-and-run-tests-utbot-java.yml/badge.svg)](https://github.com/UnitTestBot/UTBotJava/actions/workflows/build-and-run-tests-utbot-java.yml)
2+
3+
# What is UTBotJava?
4+
5+
UTBotJava generates test cases by code, trying to cover maximum statements and execution paths. We treat source code as source of truth assuming that behavior is correct and corresponds to initial user demand. Generated tests are placed in so-called regression suite. Thus, we fixate current behavior by generated test cases. Using UTBotJava developers obtain full control of their code. No future change can break the code without being noticed once it's covered with tests generated by UTBot. This way, modifications made by developers to an existing code are much safer. Hence, with the help of generated unit tests, UTBot provides dramatic code quality improvement.
6+
7+
# How to install UTBot Java IntelliJ IDEA plugin
8+
9+
For now, you can use UTBot under:
10+
- Ubuntu 20.04
11+
- Windows 10
12+
13+
See [step-by-step guide](https://github.com/UnitTestBot/UTBotJava/wiki/intellij-idea-plugin) explaining how to install UTBot Java IntelliJ IDEA plugin.
14+
15+
# How to use UTBot Java IntelliJ IDEA plugin
16+
17+
See [step-by-step guide](https://github.com/UnitTestBot/UTBotJava/wiki/Generate-tests-with-UTBot-IntelliJ-IDEA-plugin) explaining how to use UTBot Java IntelliJ IDEA plugin.
18+
19+
# How to contribute to UTBot Java
20+
21+
See [**Contributing guidelines**](CONTRIBUTING.md).

build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
group 'org.utbot'
2+
3+
apply plugin: 'java'
4+
5+
if (project.hasProperty('semVer')) {
6+
project.version = project.semVer
7+
} else {
8+
project.version = '1.0-SNAPSHOT'
9+
}
10+
11+
buildscript {
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlin_version
18+
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-allopen', version: kotlin_version
19+
}
20+
}
21+
22+
subprojects {
23+
group = rootProject.group
24+
version = rootProject.version
25+
26+
apply plugin: 'base'
27+
apply plugin: 'java'
28+
apply plugin: 'maven-publish'
29+
30+
repositories {
31+
mavenCentral()
32+
maven { url 'https://jitpack.io' }
33+
}
34+
}

docs/AndroidStudioSupport.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Android Studio support
2+
3+
## Installing AS
4+
5+
> Install latest AS <https://developer.android.com/studio/install>
6+
7+
### Installing Lombok plugin
8+
9+
> Use the first advice from the following link
10+
>
11+
> <https://stackoverflow.com/questions/70900954/cannot-find-lombok-plugin-in-android-studio-2021-1-1-build-of-2022>
12+
13+
## Prerequisites
14+
15+
> Install and setup gradle version 7.2+ (version 7.4 tested)
16+
>
17+
> Use JDK 8 for Gradle in\
18+
> `File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM`
19+
20+
## Running in AS
21+
22+
> For now, running Utbot is supported only for Kotlin libraries. You can
23+
> create one like this:
24+
>
25+
> <https://proandroiddev.com/create-an-android-library-aar-79d2338678ba>
26+
>
27+
## Debug Intellij code
28+
29+
> At first, when entering Intellij code, you might be presented with
30+
> decompiled code.
31+
>
32+
> If you try to debug it, you might soon find out that it does not match
33+
> sources.
34+
>
35+
> (TO BE TESTED)
36+
>
37+
> To fix this, you are able to connect alternative Intellij sources
38+
> using jar-files from AS.
39+
>
40+
> File -> Project Structure -> Libraries -> +
41+
>
42+
> After that, you might want to enable "Choose sources switch":
43+
>
44+
> <https://intellij-support.jetbrains.com/hc/en-us/community/posts/206822215-what-does-Choose-Sources-do-and-how-can-I-undo-what-it-does->
45+
46+
## Crucial differences from Intellij IDEA
47+
48+
### Host Android SDK
49+
50+
> Android Studio uses **host Android SDK** to build project, which is
51+
> basically **a stub(mock) version of real Android SDK**, that is
52+
> supposed to be found on a real device.
53+
>
54+
> It means that, for instance, the constructor of java.lang.Object in
55+
> that SDK throws Exception explicitly, saying "Stub!".
56+
>
57+
> The main idea is that user is not supposed to run anything on host
58+
> machine, they must use real device or emulator.
59+
>
60+
> That leads to the **inability to analyze Android SDK**, thus we have
61+
> to take real java from Gradle JDK, for example.
62+
63+
### KtClass tree in View-based modules
64+
65+
> UtBot Plugin window won't even show up if you try to analyze code from
66+
> the visual components inside AS. That is because insead of PsiClass
67+
> tree we find KtClass tree.
68+
>
69+
> TODO: There is something to be done about this...
70+
71+
## Troubleshooting
72+
73+
### Maven can't install some dependencies
74+
> 1. Proxy might have been installed automatically
75+
> Solution: remove gradle-wrapper file
76+
> 2. Mockito can't be found
77+
> Solution: specify version explicitly
78+
### No target device found
79+
> File -> Settings -> Build, Execution, Deployment -> Testing -> Run android tests with Gradle(or smth like that)
80+
81+
### Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8
82+
83+
> Solution: Use JUNIT (manually create run config for it), not Gradle!
84+
>
85+
> Also, turn off 'build before run' for tests, if you use Java 11 in your project.
86+
>
87+
> TODO: how to create config
88+
>
89+
> (!) In Generation Window, you have to set correct source root(src/test/java).
90+
91+
### Test events were not received
92+
93+
> Solution: Use JUNIT (manually create run config for it), not Gradle!
94+
>
95+
> TODO: how to create config
96+
>
97+
> (!) In Generation Window, you have to set correct source root(src/test/java).
98+
99+
### Can't run tests because Android project complains about 'tools.jar'
100+
101+
> The project is messed up, copy sources and make a clean one.
102+
>
103+
> TODO: a better solution?
104+
>
105+
### java: Cannot run program AppData/Local/Android/Sdk/bin/java
106+
107+
> The project is messed up, copy sources and make a clean one.
108+
>
109+
> TODO: a better solution?
110+
111+
### \[possible\] org.jetbrains.android not found
112+
113+
> Use latest Kotlin in UTBotJava/utbot-intellij/build.gradle:
114+
>
115+
> > intellij.plugins = [..., 'org.jetbrains.kotlin',...]

0 commit comments

Comments
 (0)