简体   繁体   English

如何在IntelliJ中运行Kotlin Koans? 什么是“主类”?

[英]How to run Kotlin Koans in IntelliJ? What is the “Main class”?

I have downloaded Kotlin Koans from Github, installed IntelliJ IDEA 2016.1.3 and opened the Koans project. 我从Github下载了Kotlin Koans,安装了IntelliJ IDEA 2016.1.3并打开了Koans项目。 As I understand I need a Configuration to run the examples. 据我所知,我需要一个Configuration来运行示例。 This Configuration needs a Main class . Configuration需要Main class I cannot figure out where I find the main class in the Kotlin Koans. 我无法弄清楚我在哪里找到Kotlin Koans的主要课程。 I have searched for one but found none (except for a special one in htmlDemo.kt ). 我搜索了一个但没有找到(除了htmlDemo.kt的特殊htmlDemo.kt )。

I see that some kind of unit test framework is used. 我看到使用了某种单元测试框架。 It probably somehow calls task0 but the IDE shows no references to task0 except one from todoTask0 . 它可能以某种方式调用task0但除了来自todoTask0之外,IDE没有显示对task0引用。 The only reference to todoTask0 is in task0 . todoTask0的唯一引用是在task0 So we have circular references but nowhere do I find an external reference to call up one of these functions. 所以我们有循环引用,但我找不到外部引用来调用其中一个函数。

Can someone explain to me how to get the Kotlin Koans running in the IntelliJ IDE? 有人可以向我解释如何在IntelliJ IDE中运行Kotlin Koans吗?

The easiest way is to install the Kotlin Edu plugin. 最简单的方法是安装Kotlin Edu插件。 You may read this JB blog post for additional info. 您可以阅读此JB博客文章以获取更多信息。

You could also run all koans tests without the plugin.IDEA allows you to run applications and tests directly from the IDE by clicking the Run icon near the test or application definition: 您也可以在没有插件的情况下运行所有​​koans测试.IDEA允许您通过单击测试或应用程序定义附近的“运行”图标直接从IDE运行应用程序和测试:

在此输入图像描述

already quite old question but I also struggled a bit. 已经很老的问题,但我也有点挣扎。 The way to do it is how they described it in their github repo (maybe they changed that since last time you checked) 这样做的方法是他们如何在他们的github回购中描述它(也许他们自上次检查后改变了)

https://github.com/Kotlin/kotlin-koans https://github.com/Kotlin/kotlin-koans

How to build and run tests 如何构建和运行测试

Working with the project using Intellij IDEA or Android Studio: 使用Intellij IDEA或Android Studio处理项目:

Import the project as Gradle project. 将项目导入为Gradle项目。 To build the project and run tests use 'test' task on Gradle panel. 要构建项目并运行测试,请使用Gradle面板上的“test”任务。

What I did: 我做了什么:

  1. Clone from github via File -> new project from version control -> github 从github通过文件克隆 - >从版本控制的新项目 - > github
  2. After that was done I also could not run anything 在那之后我也无法运行任何东西
  3. File -> New Project from existing soure -> Choose your folder 文件 - >来自现有源的新项目 - >选择您的文件夹
  4. Import Project from external model -> choose Gradle 从外部模型导入项目 - >选择Gradle
  5. No need to change anything, after that it worked for me 没有必要改变任何东西,之后它对我有用

Follow the documentation : 按照文档

  1. Open up the project in IntelliJ IDEA or your favorite editor. 在IntelliJ IDEA或您喜欢的编辑器中打开项目。 Note: If IntelliJ IDEA prompts you to update the Kotlin library, just click yes. 注意:如果IntelliJ IDEA提示您更新Kotlin库,只需单击是。

  2. Run a test. 运行测试。 Make it pass 让它通过

You can trigger a test run by opening a file (ie kotlin-koans/test/i_introduction/_0_Hello_World/_00_Start.kt ) and hitting: 您可以通过打开文件(即kotlin-koans/test/i_introduction/_0_Hello_World/_00_Start.kt )触发测试运行并点击: 在此输入图像描述

You can find more information about running tests in IntelliJ in the documentation . 您可以在文档中找到有关在IntelliJ中运行测试的更多信息。

In my case, it is the zsh 's bug, can be solved in following: 就我而言,它是zsh的bug,可以通过以下方式解决:

  1. add setopt no_nomatch in the end of file ~/.zshrc ; 在文件~/.zshrc setopt no_nomatch的末尾添加setopt no_nomatch ;
  2. then run source /.zshrc 然后运行source /.zshrc

You can run them by clicking the Check Task button. 您可以通过单击“ 检查任务”按钮来运行它们。 :) :)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM